1 | var assert = require("assert");
|
2 | var file = require('../file-system');
|
3 | var fs = require('fs');
|
4 | var path = require('path');
|
5 |
|
6 | function getPath(filepath) {
|
7 | return path.join(__dirname, filepath);
|
8 | }
|
9 |
|
10 | describe('copy file async', function() {
|
11 | before(function() {
|
12 | file.writeFileSync(getPath('var/copy-file/index.html'), 1);
|
13 | });
|
14 | });
|
15 |
|
16 | describe('copy file', function() {
|
17 | before(function() {
|
18 | file.writeFileSync(getPath('var/copy-file/index.html'), 1);
|
19 | });
|
20 |
|
21 | describe('copy file async', function() {
|
22 | it('only copy', function(done) {
|
23 | var oldpath = getPath('var/copy-file/index.html');
|
24 | var newpath = getPath('var/copy-file/dest/index.async.dest.html');
|
25 |
|
26 | file.copyFile(oldpath, newpath, {
|
27 | process: function() {
|
28 | return 2;
|
29 | },
|
30 | done: function() {
|
31 | var contents = file.readFileSync(newpath, { encoding: 'utf8' });
|
32 | assert.equal(2, contents);
|
33 | assert.equal(true, file.existsSync(newpath));
|
34 | done();
|
35 | }
|
36 | });
|
37 | });
|
38 |
|
39 | it('copy image', function(done) {
|
40 | var oldpath = getPath('test.png');
|
41 | var newpath = getPath('var/copy-file/test.async.dest.png');
|
42 |
|
43 | file.copyFile(oldpath, newpath, {
|
44 | done: function() {
|
45 | assert.equal(file.readFileSync(oldpath).length, file.readFileSync(newpath).length);
|
46 | done();
|
47 | }
|
48 | });
|
49 | });
|
50 | });
|
51 |
|
52 | describe('copy file sync', function() {
|
53 | it('only copy', function() {
|
54 | var oldpath = getPath('var/copy-file/index.html');
|
55 | var newpath = getPath('var/copy-file/dest/index.dest.html');
|
56 |
|
57 | file.copyFileSync(oldpath, newpath);
|
58 | assert.equal(true, file.existsSync(newpath));
|
59 | });
|
60 |
|
61 | it('copy with process', function() {
|
62 | var oldpath = getPath('var/copy-file/index.html');
|
63 | var newpath = getPath('var/copy-file/dest/index.dest.html');
|
64 |
|
65 | file.copyFileSync(oldpath, newpath, {
|
66 | process: function(contents) {
|
67 | return 2;
|
68 | }
|
69 | });
|
70 |
|
71 | var contents = file.readFileSync(newpath, { encoding: 'utf8' });
|
72 |
|
73 | assert.equal(2, contents);
|
74 | });
|
75 |
|
76 | it('copy image', function() {
|
77 | var oldpath = getPath('test.png');
|
78 | var newpath = getPath('var/copy-file/test.dest.png');
|
79 |
|
80 | file.copyFileSync(oldpath, newpath);
|
81 | assert.equal(file.readFileSync(oldpath).length, file.readFileSync(newpath).length);
|
82 | });
|
83 | });
|
84 |
|
85 | after(function() {
|
86 | file.rmdirSync(getPath('var/copy-file'));
|
87 | });
|
88 | }); |
\ | No newline at end of file |