/
runner.cli.spec.js
124 lines (98 loc) · 3.62 KB
/
runner.cli.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* Use Case
* Runs the CLI fixture that copies dot files from fixtures directory. Based
* on copy-dots: https://github.com/thescientist13/copy-dots
*
* User Result
* Should run cli.js runCommand successfully with setup, runCommand and teardown functions called
*
* runCommand
* runCommand('test/fixtures/cli', 'test/fixtures')
*
*/
import chai from 'chai';
import fs from 'fs-extra';
import path from 'path';
import { Runner } from '../../../src/index.js';
import { fileURLToPath, URL } from 'url';
const expect = chai.expect;
describe('CLI Fixture', function() {
const outputPath = fileURLToPath(new URL('./output', import.meta.url));
const fixturesPath = path.join(process.cwd(), 'test/fixtures');
const setupFiles = [{
source: path.join(process.cwd(), 'node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js'),
destination: path.join(outputPath, 'webcomponents-bundle.js')
}];
describe('default options with relative path', function() {
let runner;
before(function() {
runner = new Runner();
runner.setup(outputPath);
runner.runCommand(
`${fixturesPath}/cli.js`, // binPath
fixturesPath // args
);
});
it('should have created the output folder', function() {
const exists = fs.existsSync(outputPath);
expect(exists).to.be.equal(true);
});
it('should only copy 3 files', function() {
const files = fs.readdirSync(outputPath);
expect(files.length).to.be.equal(3);
});
it('should have an .editorconfig file', function() {
expect(fs.existsSync(`${outputPath}/.editorconfig`)).to.be.equal(true);
});
it('should have an .eslintrc file', function() {
expect(fs.existsSync(`${outputPath}/.eslintrc.cjs`)).to.be.equal(true);
});
it('should have .mocharc file', function() {
expect(fs.existsSync(`${outputPath}/.mocharc.cjs`)).to.be.equal(true);
});
it('should delete the output directory when told', function() {
runner.teardown([outputPath]);
expect(fs.existsSync(outputPath)).to.be.equal(false);
});
});
describe('setup with setupFiles', function() {
let runner;
before(function() {
runner = new Runner();
runner.setup(outputPath, setupFiles);
runner.runCommand(
`${fixturesPath}/cli.js`, // binPath
fixturesPath // args
);
});
it('should have created the output folder', function() {
const exists = fs.existsSync(outputPath);
expect(exists).to.be.equal(true);
});
it('should only copy 4 files', function() {
const files = fs.readdirSync(outputPath);
expect(files.length).to.be.equal(4);
});
it('should have an .editorconfig file', function() {
expect(fs.existsSync(`${outputPath}/.editorconfig`)).to.be.equal(true);
});
it('should have an .eslintrc file', function() {
expect(fs.existsSync(`${outputPath}/.eslintrc.cjs`)).to.be.equal(true);
});
it('should have .mocharc file', function() {
expect(fs.existsSync(`${outputPath}/.mocharc.cjs`)).to.be.equal(true);
});
it('should have webcomponents-bundle.js file', function() {
expect(fs.existsSync(`${outputPath}/webcomponents-bundle.js`)).to.be.equal(true);
});
it('should delete the setup file we provided', function() {
const setupFile = path.join(outputPath, 'webcomponents-bundle.js');
runner.teardown();
expect(fs.existsSync(setupFile)).to.be.equal(false);
expect(fs.existsSync(outputPath)).to.be.equal(true);
// cleanup everything
runner.teardown([outputPath]);
expect(fs.existsSync(outputPath)).to.be.equal(false);
});
});
});