Skip to content

Commit ec271c7

Browse files
committed
test: coverage
1 parent 60d4a12 commit ec271c7

6 files changed

Lines changed: 36 additions & 25 deletions

File tree

e2e/__helpers__/test-case.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ function prepareTest(
370370
fs.outputFileSync(join(caseWorkdir, '__eval.ts'), EVAL_SOURCE, 'utf8');
371371
let ioDir!: string;
372372
if (options.writeIo) {
373-
ioDir = join(caseWorkdir, '__io');
373+
ioDir = join(caseWorkdir, '__io__');
374374
fs.mkdirpSync(ioDir);
375375
}
376376
const hooksFile = join(caseWorkdir, '__hooks.js');

e2e/jest.config.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
const base = require('../jest.config');
2-
3-
module.exports = Object.assign({}, base, {
4-
rootDir: '.',
5-
testRegex: '/__tests__/.+\\.(test|spec)\\.ts$',
6-
coverageDirectory: '<rootDir>/../coverage/e2e',
7-
snapshotSerializers: ['<rootDir>/__serializers__/test-run-result.ts'],
8-
});
1+
module.exports = {
2+
rootDir: '..',
3+
transform: {
4+
'\\.ts$': '<rootDir>/dist/index.js',
5+
},
6+
testMatch: ['<rootDir>/e2e/__tests__/**/?(*.)+(spec|test).ts?(x)'],
7+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
8+
testEnvironment: 'node',
9+
snapshotSerializers: ['<rootDir>/e2e/__serializers__/test-run-result.ts'],
10+
};

jest.config.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
module.exports = {
2-
rootDir: 'src',
2+
rootDir: '.',
33
transform: {
4-
'\\.ts$': '<rootDir>/../dist/index.js',
4+
'\\.ts$': '<rootDir>/dist/index.js',
55
},
6-
testRegex: '\\.(spec|test)\\.ts$',
7-
coverageDirectory: '<rootDir>/../coverage/unit',
6+
testMatch: ['<rootDir>/src/**/?(*.)+(spec|test).ts?(x)'],
87
collectCoverageFrom: [
9-
'<rootDir>/../src/**/*.ts',
10-
'!<rootDir>/../src/**/*.spec.ts',
11-
'!<rootDir>/../src/**/*.test.ts',
12-
'!<rootDir>/../src/**/__*__/',
8+
'<rootDir>/src/**/*.ts',
9+
'!<rootDir>/src/**/*.spec.ts',
10+
'!<rootDir>/src/**/*.test.ts',
11+
'!<rootDir>/src/**/__*__/*',
1312
],
1413
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
1514
testEnvironment: 'node',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"build:watch": "tsc -p tsconfig.build.json -w",
1111
"clean": "node scripts/clean.js",
1212
"pretest": "npm run lint",
13-
"test": "run-s -s \"test:e2e -- {@}\" \"test:unit -- {@}\" --",
13+
"test": "run-s -s test:e2e \"test:unit -- {@}\" --",
1414
"test:e2e": "node scripts/e2e.js",
1515
"test:unit": "jest",
1616
"lint": "tslint --project .",

scripts/e2e.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ const npmVersion = spawnSync('npm', ['-s', '--version'])
1515
const npmHasCiCommand = satisfies(npmVersion, '>=5.7.0');
1616
const npmHasPrepare = satisfies(npmVersion, '>=4.0.0');
1717

18+
const configFile = path.resolve(__dirname, '..', 'e2e', 'jest.config.js');
19+
let parentArgs = process.argv.slice(2);
20+
if (parentArgs.includes('--coverage')) {
21+
console.warn(
22+
'Coverages cannot be activated for e2e tests (but can in each e2e test).'
23+
);
24+
parentArgs = parentArgs.filter(a => a !== '--coverage');
25+
}
26+
1827
function getDirectories(rootDir) {
1928
return fs.readdirSync(rootDir).filter(function(file) {
2029
return fs.statSync(path.join(rootDir, file)).isDirectory();
@@ -135,12 +144,14 @@ function setupE2e() {
135144
});
136145
}
137146

147+
// ============================================================================
148+
138149
setupE2e();
139150

140-
log('templates are ready, running tests', '\n\n');
151+
log('templates are ready, clearing Jest cache');
152+
153+
spawnSync('jest', ['--clearCache']);
154+
155+
log('running tests');
141156

142-
jest.run([
143-
'--config',
144-
path.resolve(__dirname, '..', 'e2e', 'jest.config.js'),
145-
...process.argv.slice(2),
146-
]);
157+
jest.run(['--config', configFile, ...parentArgs]);

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"resolveJsonModule": true,
2020
"lib": ["es2015", "es2016.array.include"],
2121
"types": ["jest", "node"],
22-
"sourceRoot": "src"
2322
},
2423
"include": [
2524
"src",

0 commit comments

Comments
 (0)