Skip to content

Commit 7ddac8e

Browse files
committed
tests(webpack-cli): install all packages before launching the tests
1 parent 60bcd0a commit 7ddac8e

File tree

4 files changed

+65
-12
lines changed

4 files changed

+65
-12
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@
2525
"scripts": {
2626
"bootstrap": "lerna bootstrap",
2727
"build": "node scripts/buildPackages.js",
28+
"prepsuite": "node scripts/prepareSuite.js",
2829
"clean:all": "rimraf node_modules packages/*/{node_modules}",
2930
"commit": "git-cz",
3031
"docs": "typedoc",
3132
"format": "eslint --fix . --ext .js,.ts",
3233
"lint": "eslint . --ext .js,.ts",
3334
"lint:fix": "eslint . --ext .js,.ts --fix",
34-
"pretest": "yarn build && yarn lint",
35+
"pretest": "yarn build && yarn lint && yarn prepsuite",
3536
"reportCoverage": "nyc report --reporter=json && codecov -f coverage/coverage-final.json --disable=gcov",
3637
"smoketest": "smoketests/smoketests.sh",
3738
"test": "nyc jest --maxWorkers=4 --reporters=default --reporters=jest-junit",

scripts/prepareSuite.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
// eslint-disable-next-line node/no-unpublished-require
6+
const execa = require('execa');
7+
// eslint-disable-next-line node/no-unpublished-require
8+
const chalk = require('chalk');
9+
10+
const BASE_DIR = 'test/';
11+
const PACKAGE = 'package.json';
12+
13+
function collectTestingFoldersWithPackage() {
14+
const testFolder = path.resolve(path.join(process.cwd(), BASE_DIR));
15+
16+
return extractFolder(testFolder);
17+
}
18+
19+
function extractFolder(folderToRead, folders = []) {
20+
const files = fs.readdirSync(folderToRead);
21+
22+
files.forEach(file => {
23+
const filePath = path.resolve(path.join(folderToRead, file));
24+
const stats = fs.statSync(filePath);
25+
if (stats.isFile() && file === PACKAGE) {
26+
folders.push(folderToRead);
27+
}
28+
if (stats.isDirectory() && file !== 'node_modules') {
29+
extractFolder(filePath, folders);
30+
}
31+
});
32+
33+
return folders;
34+
}
35+
36+
{
37+
Promise.all(
38+
collectTestingFoldersWithPackage().map(async folder => {
39+
return execa('yarn', {
40+
cwd: folder,
41+
stdio: 'inherit',
42+
});
43+
}),
44+
)
45+
.then(() => {
46+
console.log(chalk.inverse.green(' Successfully prepared the test suite '));
47+
})
48+
.catch(e => {
49+
console.error(chalk.inverse.red(' Unable to prepare the test suite '));
50+
console.error(e.stack);
51+
process.exitCode = 1;
52+
});
53+
}

test/entry/scss/home.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
body {
22
font-size: 100%;
3+
body {
4+
background-color: red;
5+
}
36
}

test/entry/scss/scss.test.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@ const { run, runInstall } = require('../../utils/test-utils');
55
jest.setTimeout(1000 * 60 * 5);
66

77
describe('entry point', () => {
8-
it(
9-
'should support SCSS files',
10-
async () => {
11-
await runInstall(__dirname);
12-
const { stdout } = run(__dirname);
13-
expect(stdout).toBeTruthy();
14-
expect(stdout).toContain('home.scss');
15-
expect(stdout).toContain('home.js');
16-
},
17-
1000 * 60 * 5,
18-
);
8+
it('should support SCSS files', async () => {
9+
await runInstall(__dirname);
10+
const { stdout } = run(__dirname);
11+
expect(stdout).toBeTruthy();
12+
expect(stdout).toContain('home.scss');
13+
expect(stdout).toContain('home.js');
14+
});
1915
});

0 commit comments

Comments
 (0)