1 |
|
2 |
|
3 | var path = require('path');
|
4 |
|
5 | var shell = require('shelljs');
|
6 |
|
7 | var chai = require('chai');
|
8 | var chaiFiles = require('chai-files');
|
9 |
|
10 | chai.use(chaiFiles);
|
11 |
|
12 | var expect = chai.expect;
|
13 | var file = chaiFiles.file;
|
14 |
|
15 | var rimraf = require("rimraf");
|
16 |
|
17 | var copyFilesFromTo = require('../index.js');
|
18 |
|
19 | describe('package', function() {
|
20 | describe('copy-files-from-to', function() {
|
21 | this.timeout(10000);
|
22 |
|
23 |
|
24 | it('should load fine when using require', function(done) {
|
25 | done();
|
26 | });
|
27 |
|
28 | it('should be able to copy files from a json config', function (done) {
|
29 | var basicUsageDir = path.join(__dirname, 'basic-usage');
|
30 |
|
31 | rimraf.sync(path.join(basicUsageDir, 'scripts'));
|
32 |
|
33 | var
|
34 | consolePanelJsOriginal = path.join(basicUsageDir, 'expected-output', 'scripts', 'console-panel', 'console-panel.js'),
|
35 | consolePanelJs = path.join(basicUsageDir, 'scripts', 'console-panel', 'console-panel.js'),
|
36 |
|
37 | consolePanelCssOriginal = path.join(basicUsageDir, 'expected-output', 'scripts', 'console-panel', 'console-panel.css'),
|
38 | consolePanelCss = path.join(basicUsageDir, 'scripts', 'console-panel', 'console-panel.css'),
|
39 |
|
40 | jqueryJsOriginal = path.join(basicUsageDir, 'node_modules', 'jquery', 'dist', 'jquery.js'),
|
41 | jqueryJs = path.join(basicUsageDir, 'scripts', 'jquery', 'jquery.js');
|
42 |
|
43 | shell.exec(
|
44 | path.join(__dirname, '..', 'index.js'),
|
45 | {
|
46 | silent: true,
|
47 | cwd: basicUsageDir
|
48 | },
|
49 | function (exitCode, stdout, stderr) {
|
50 | expect(file(jqueryJs)).to.equal(file(jqueryJsOriginal));
|
51 | expect(file(consolePanelJs)).to.equal(file(consolePanelJsOriginal));
|
52 | expect(file(consolePanelCss)).to.equal(file(consolePanelCssOriginal));
|
53 |
|
54 | done();
|
55 | }
|
56 | );
|
57 | });
|
58 |
|
59 | it('should be able to copy files from a cjson config', function (done) {
|
60 | var advancedUsageDir = path.join(__dirname, 'advanced-usage');
|
61 |
|
62 | rimraf.sync(path.join(advancedUsageDir, 'public'));
|
63 | rimraf.sync(path.join(advancedUsageDir, 'scripts'));
|
64 |
|
65 | var
|
66 | underscoreJsOriginal = path.join(advancedUsageDir, 'expected-output', 'scripts', 'underscore.js'),
|
67 | underscoreJs = path.join(advancedUsageDir, 'scripts', 'underscore.js'),
|
68 |
|
69 | consolePanelJsOriginal = path.join(advancedUsageDir, 'expected-output', 'scripts', 'console-panel', 'console-panel.js'),
|
70 | consolePanelJs = path.join(advancedUsageDir, 'scripts', 'console-panel', 'console-panel.js'),
|
71 |
|
72 | aJpgOriginal = path.join(advancedUsageDir, 'expected-output', 'public', 'images', 'test-a', 'a.jpg'),
|
73 | bJpgOriginal = path.join(advancedUsageDir, 'expected-output', 'public', 'images', 'test-b', 'b.jpg'),
|
74 | cTxtOriginal = path.join(advancedUsageDir, 'expected-output', 'public', 'images', 'test-c', 'c.txt'),
|
75 |
|
76 | aJpg = path.join(advancedUsageDir, 'public', 'images', 'test-a', 'a.jpg'),
|
77 | bJpg = path.join(advancedUsageDir, 'public', 'images', 'test-b', 'b.jpg'),
|
78 | cTxt = path.join(advancedUsageDir, 'public', 'images', 'test-c', 'c.txt'),
|
79 |
|
80 | aJpgFlat = path.join(advancedUsageDir, 'public', 'copy-to-flat-directory', 'a.jpg'),
|
81 | bJpgFlat = path.join(advancedUsageDir, 'public', 'copy-to-flat-directory', 'b.jpg'),
|
82 | cTxtFlat = path.join(advancedUsageDir, 'public', 'copy-to-flat-directory', 'c.txt');
|
83 |
|
84 | shell.exec(
|
85 | path.join(__dirname, '..', 'index.js'),
|
86 | {
|
87 | silent: true,
|
88 | cwd: advancedUsageDir
|
89 | },
|
90 | function (exitCode, stdout, stderr) {
|
91 | expect(file(underscoreJs)).to.equal(file(underscoreJsOriginal));
|
92 | expect(file(consolePanelJs)).to.equal(file(consolePanelJsOriginal));
|
93 |
|
94 | expect(file(aJpg)).to.equal(file(aJpgOriginal));
|
95 | expect(file(bJpg)).to.equal(file(bJpgOriginal));
|
96 | expect(file(cTxt)).to.equal(file(cTxtOriginal));
|
97 |
|
98 | expect(file(aJpgFlat)).to.equal(file(aJpgOriginal));
|
99 | expect(file(bJpgFlat)).to.equal(file(bJpgOriginal));
|
100 | expect(file(cTxtFlat)).to.equal(file(cTxtOriginal));
|
101 |
|
102 | done();
|
103 | }
|
104 | );
|
105 | });
|
106 |
|
107 | it('should be able to copy a file in custom mode', function (done) {
|
108 | var dirToUse = path.join(__dirname, 'test-copy-file-in-custom-mode');
|
109 |
|
110 | rimraf.sync(path.join(dirToUse, 'scripts'));
|
111 |
|
112 | var
|
113 | underscoreJsMapOriginal = path.join(dirToUse, 'expected-output', 'scripts', 'underscore.js.map'),
|
114 | underscoreJsMap = path.join(dirToUse, 'scripts', 'underscore.js.map');
|
115 |
|
116 | shell.exec(
|
117 | path.join(__dirname, '..', 'index.js') + ' --mode pre-production',
|
118 | {
|
119 | silent: true,
|
120 | cwd: dirToUse
|
121 | },
|
122 | function (exitCode, stdout, stderr) {
|
123 | expect(file(underscoreJsMap)).to.equal(file(underscoreJsMapOriginal));
|
124 |
|
125 | done();
|
126 | }
|
127 | );
|
128 | });
|
129 |
|
130 | it('should be able to copy files from parent folder', function (done) {
|
131 | var testCopyFilesFromParentFolderDir = path.join(__dirname, 'test-copy-files-from-parent-folder');
|
132 | var cwdToUse = path.join(testCopyFilesFromParentFolderDir, 'folder-input-1', 'folder-input-2');
|
133 |
|
134 | rimraf.sync(path.join(testCopyFilesFromParentFolderDir, 'dest'));
|
135 |
|
136 | var
|
137 | consolePanelJsOriginal = path.join(testCopyFilesFromParentFolderDir, 'code', 'console-panel.js'),
|
138 | consolePanelCssOriginal = path.join(testCopyFilesFromParentFolderDir, 'code', 'console-panel.css'),
|
139 |
|
140 | consolePanelJsGlob1 = path.join(testCopyFilesFromParentFolderDir, 'dest', 'folder-output-1', 'console-panel.js'),
|
141 | consolePanelCssGlob1 = path.join(testCopyFilesFromParentFolderDir, 'dest', 'folder-output-1', 'console-panel.css'),
|
142 |
|
143 | consolePanelJsGlob2 = path.join(testCopyFilesFromParentFolderDir, 'dest', 'folder-output-2', 'console-panel.js'),
|
144 | consolePanelCssGlob2 = path.join(testCopyFilesFromParentFolderDir, 'dest', 'folder-output-2', 'console-panel.css');
|
145 |
|
146 | shell.exec(
|
147 | path.join(__dirname, '..', 'index.js'),
|
148 | {
|
149 | silent: true,
|
150 | cwd: cwdToUse
|
151 | },
|
152 | function (exitCode, stdout, stderr) {
|
153 | expect(file(consolePanelJsGlob1)).to.equal(file(consolePanelJsOriginal));
|
154 | expect(file(consolePanelCssGlob1)).to.equal(file(consolePanelCssOriginal));
|
155 |
|
156 | expect(file(consolePanelJsGlob2)).to.equal(file(consolePanelJsOriginal));
|
157 | expect(file(consolePanelCssGlob2)).to.equal(file(consolePanelCssOriginal));
|
158 |
|
159 | done();
|
160 | }
|
161 | );
|
162 | });
|
163 |
|
164 | it('should be able to read copy instructions from package.json file as a fallback', function (done) {
|
165 | var cwdToUse = path.join(__dirname, 'test-copy-instructions-from-package-json');
|
166 |
|
167 | rimraf.sync(path.join(cwdToUse, 'scripts'));
|
168 |
|
169 |
|
170 |
|
171 | var
|
172 | jqueryJsOriginal = path.join(cwdToUse, 'node_modules', 'jquery', 'dist', 'jquery.js'),
|
173 | jqueryJs = path.join(cwdToUse, 'scripts', 'jquery', 'jquery.js');
|
174 |
|
175 | shell.exec(
|
176 | path.join(__dirname, '..', 'index.js'),
|
177 | {
|
178 | silent: true,
|
179 | cwd: cwdToUse
|
180 | },
|
181 | function (exitCode, stdout, stderr) {
|
182 | expect(file(jqueryJs)).to.equal(file(jqueryJsOriginal));
|
183 |
|
184 | done();
|
185 | }
|
186 | );
|
187 | });
|
188 | });
|
189 | });
|