Skip to content

Commit fd72b8d

Browse files
committed
tests: all versions
1 parent 177f6bf commit fd72b8d

File tree

1 file changed

+58
-27
lines changed

1 file changed

+58
-27
lines changed

tests/test.js

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,69 @@ const os = require('os');
44
const packageName = 'html5-boilerplate';
55
const tempDir = os.tmpdir()+`/${packageName}-staging`;
66

7-
const originalArgv = process.argv;
87

9-
describe('Filesystem test', () => {
10-
beforeAll(async () => {
11-
process.argv.push('./out', '-r=7.2.0');
12-
await cli();
13-
});
14-
afterAll(async () => {
15-
fs.remove('./out');
16-
process.argv = originalArgv;
17-
});
18-
test('./out directory exists', async() => {
19-
const outDirExists = await fs.exists('./out');
20-
expect(outDirExists).toBe(true);
21-
});
22-
test('./out directory have files', async() => {//TODO: check files exists e.g index.html, package.json
23-
const dirContents = await fs.readdir('./out');
24-
expect(dirContents.length).toBeGreaterThanOrEqual(5);
25-
});
26-
test('Temp dir removed', async() => {
27-
const tempDirExists = await fs.exists(tempDir);
28-
expect(tempDirExists).toBe(false);
29-
});
8+
// TODO: fetch all versions:
9+
// const { packument } = require('pacote');
10+
// const versions = await packument(packageName);
11+
// cases = ['', 'latest', '-r=7.3.0', ...Object.keys(versions)];
12+
const all_versions = ['0.0.1','5.3.0',
13+
'6.0.0', '6.0.1',
14+
'6.1.0', '7.0.0',
15+
'7.0.1', '7.1.0',
16+
'7.2.0', '7.3.0'];
17+
const cases = ['-r=7.2.0','-r=v7.2.0','-r=v7.2', '--release=7.3.0', ...all_versions.map(v=>'-r='+v)];
18+
describe.each(cases)(
19+
"Downloading %s",
20+
(version) => {
21+
beforeAll(async () => {
22+
jest.spyOn(process, 'exit').mockImplementationOnce(() => {
23+
throw new Error('process.exit() was called.'+version)
24+
});
25+
process.argv.push(`./out/${version}`);
26+
if(version){
27+
process.argv.push(version)
28+
}
29+
await cli();
30+
process.argv = process.argv.filter(v=>v!==version && v !== `./out/${version}`);//revert process args
31+
});
32+
afterAll(async () => {
33+
await fs.remove(`./out/${version}`);
34+
});
35+
36+
if(version){
37+
test(`version ${version}`, async() => {
38+
const cssContent = await fs.readFile(`./out/${version}/css/main.css`, 'utf-8');
39+
let versionClear = version.replace(/(-r=|--release=|v)/gi, '');
40+
if(versionClear === '7.0.0'){ versionClear = '6.1.0'}
41+
if(versionClear === '0.0.1'){ versionClear = '5.3.0'}
42+
expect(cssContent.indexOf(`HTML5 Boilerplate v${versionClear}`) > -1).toBe(true);
43+
});
44+
}
45+
46+
test('./out directory exists', async() => {
47+
const outDirExists = await fs.exists(`./out/${version}`);
48+
expect(outDirExists).toBe(true);
49+
});
50+
test('./out directory have files', async() => {
51+
const dirContents = await fs.readdir(`./out/${version}`);
52+
expect(dirContents.length).toBeGreaterThanOrEqual(5);
53+
});
54+
test('./out directory specific files', async() => {
55+
const dirContents = await fs.readdir(`./out/${version}`);
56+
const check = ['index.html', 'robots.txt','tile.png', 'css', 'js', 'img'].filter(v=>dirContents.indexOf(v)=== -1);
57+
expect(check.length === 0).toBe(true);
58+
});
59+
test('Temp dir removed', async() => {
60+
const tempDirExists = await fs.exists(tempDir);
61+
expect(tempDirExists).toBe(false);
62+
});
63+
}
64+
);
3065
// test('Attempt 1', async() => {
3166
// const spy = jest.spyOn(console, 'log');
32-
// jest.spyOn(process, 'exit').mockImplementationOnce(() => {
33-
// throw new Error('process.exit() was called.')
34-
// });
3567

3668
// expect(() => {
3769
// }).toThrow('process.exit() was called.');
3870
// expect(spy.mock.calls).toEqual([['Testing...']]);
3971
// expect(process.exit).toHaveBeenCalledWith(0);
40-
// });
41-
});
72+
// });

0 commit comments

Comments
 (0)