UNPKG

2.42 kBJavaScriptView Raw
1var assert = require("assert");
2var file = require('../file-system');
3var fs = require('fs');
4var path = require('path');
5
6function getPath(filepath) {
7 return path.join(__dirname, filepath);
8}
9
10describe('copy file async', function() {
11 before(function() {
12 file.writeFileSync(getPath('var/copy-file/index.html'), 1);
13 });
14});
15
16describe('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() {
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 }
47 });
48 });
49 });
50
51 describe('copy file sync', function() {
52 it('only copy', function() {
53 var oldpath = getPath('var/copy-file/index.html');
54 var newpath = getPath('var/copy-file/dest/index.dest.html');
55
56 file.copyFileSync(oldpath, newpath);
57 assert.equal(true, file.existsSync(newpath));
58 });
59
60 it('copy with process', function() {
61 var oldpath = getPath('var/copy-file/index.html');
62 var newpath = getPath('var/copy-file/dest/index.dest.html');
63
64 file.copyFileSync(oldpath, newpath, {
65 process: function(contents) {
66 return 2;
67 }
68 });
69
70 var contents = file.readFileSync(newpath, { encoding: 'utf8' });
71
72 assert.equal(2, contents);
73 });
74
75 it('copy image', function() {
76 var oldpath = getPath('test.png');
77 var newpath = getPath('var/copy-file/test.dest.png');
78
79 file.copyFileSync(oldpath, newpath);
80 assert.equal(file.readFileSync(oldpath).length, file.readFileSync(newpath).length);
81 });
82 });
83
84 after(function() {
85 file.rmdirSync(getPath('var/copy-file'));
86 });
87});
\No newline at end of file