Skip to content

Commit 683a1e5

Browse files
committed
fix(tests): detect npm version to use or not ci
1 parent 3e4de3e commit 683a1e5

8 files changed

Lines changed: 56 additions & 51 deletions

File tree

.travis.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,5 @@ node_js:
1010
- "6"
1111
before_install:
1212
- sudo sysctl fs.inotify.max_user_watches=524288
13-
- npm i -g greenkeeper-lockfile@1 rimraf
14-
before_script:
15-
# - greenkeeper-lockfile-update
1613
script:
1714
- npm test
18-
after_script:
19-
# - greenkeeper-lockfile-upload

appveyor.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ install:
2323
- ps: Install-Product node $env:nodejs_version
2424
- set CI=true
2525
- set AppVeyor=true
26-
- npm i -g rimraf
2726
- npm ci || npm install
2827

2928
build: off

e2e/__helpers__/test-case.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,25 @@ export default function configureTestCase(
130130
}
131131

132132
export function sanitizeOutput(output: string): string {
133-
return (
134-
output
135-
.trim()
136-
// removes total and estimated times
137-
.replace(
138-
/^(\s*Time\s*:\s*)[\d.]+m?s(?:(,\s*estimated\s+)[\d.]+m?s)?(\s*)$/gm,
139-
(_, start, estimatedPrefix, end) => {
140-
return `${start}XXs${
141-
estimatedPrefix ? `${estimatedPrefix}YYs` : ''
142-
}${end}`;
143-
},
144-
)
145-
// removes each test time values
146-
.replace(
147-
/^(\s*(?:|)\s+.+\s+\()[\d.]+m?s(\)\s*)$/gm,
148-
(_, start, end) => `${start}XXms${end}`,
149-
)
150-
);
133+
let out: string = output
134+
.trim()
135+
// removes total and estimated times
136+
.replace(
137+
/^(\s*Time\s*:\s*)[\d.]+m?s(?:(,\s*estimated\s+)[\d.]+m?s)?(\s*)$/gm,
138+
(_, start, estimatedPrefix, end) => {
139+
return `${start}XXs${end}`;
140+
},
141+
)
142+
// removes each test time values
143+
.replace(
144+
/^(\s*(?:|×||)\s+.+\s+\()[\d.]+m?s(\)\s*)$/gm,
145+
(_, start, end) => `${start}XXms${end}`,
146+
);
147+
// TODO: improves this...
148+
if (process.platform === 'win32') {
149+
out = out.replace(/\\/g, '/');
150+
}
151+
return out;
151152
}
152153

153154
export function run(

e2e/__tests__/__snapshots__/source-map.spec.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Object {
3232
Test Suites: 1 failed, 1 total
3333
Tests: 1 failed, 1 total
3434
Snapshots: 0 total
35-
Time: XXs, estimated YYs
35+
Time: XXs
3636
Ran all test suites.
3737
================================================================================,
3838
"with-babel-7": jest exit code: 1
@@ -65,7 +65,7 @@ Object {
6565
Test Suites: 1 failed, 1 total
6666
Tests: 1 failed, 1 total
6767
Snapshots: 0 total
68-
Time: XXs, estimated YYs
68+
Time: XXs
6969
Ran all test suites.
7070
================================================================================,
7171
"with-jest-22": jest exit code: 1
@@ -97,7 +97,7 @@ Object {
9797
Test Suites: 1 failed, 1 total
9898
Tests: 1 failed, 1 total
9999
Snapshots: 0 total
100-
Time: XXs, estimated YYs
100+
Time: XXs
101101
Ran all test suites.
102102
================================================================================,
103103
}

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
"types": "./dist/index.d.ts",
66
"description": "A preprocessor with sourcemap support to help use Typescript with Jest",
77
"scripts": {
8+
"prebuild": "node scripts/clean-dist.js",
89
"build": "tsc -p tsconfig.build.json",
910
"build:watch": "tsc -p tsconfig.build.json -w",
1011
"clean": "node scripts/clean.js",
11-
"pretest": "npm run tslint",
12+
"pretest": "npm run lint",
1213
"test": "node scripts/e2e.js",
13-
"tslint": "tslint 'src/**/*.ts'",
14+
"lint": "tslint 'src/**/*.ts'",
1415
"doc": "doctoc .",
15-
"prepare": "rimraf dist && npm run build",
16+
"prepare": "npm run build",
1617
"prepublishOnly": "npm run test",
1718
"precommit": "lint-staged",
1819
"postcommit": "git reset",
@@ -54,7 +55,7 @@
5455
"lint-staged": "^7.2.0",
5556
"prettier": "^1.14.1",
5657
"reflect-metadata": "^0.1.12",
57-
"rimraf": "^2.6.2",
58+
"semver": "^5.5.0",
5859
"tslint": "^5.11.0",
5960
"typescript": "^2.9.2"
6061
},

scripts/clean-dist.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env node
2+
3+
const { removeSync } = require('fs-extra');
4+
const Paths = require('./paths');
5+
6+
removeSync(Paths.distDir);

scripts/clean.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/usr/bin/env node
22

3-
const rimraf = require('rimraf');
3+
const { removeSync } = require('fs-extra');
44
const Paths = require('./paths');
55
const { join } = require('path');
66

7-
rimraf.sync(Paths.distDir);
8-
rimraf.sync(join(Paths.testsRootDir, '*', 'coverage'));
9-
rimraf.sync(join(Paths.testsRootDir, '*', 'debug.txt'));
10-
rimraf.sync(join(Paths.testsRootDir, '*', 'node_modules'));
11-
rimraf.sync(join(Paths.e2eSourceDir, '*', 'node_modules'));
12-
rimraf.sync(join(Paths.e2eTemplatesDir, '*', 'node_modules'));
13-
rimraf.sync(Paths.e2eWorkDir);
14-
rimraf.sync(Paths.e2eWotkDirLink);
7+
removeSync(Paths.distDir);
8+
removeSync(join(Paths.testsRootDir, '*', 'coverage'));
9+
removeSync(join(Paths.testsRootDir, '*', 'debug.txt'));
10+
removeSync(join(Paths.testsRootDir, '*', 'node_modules'));
11+
removeSync(join(Paths.e2eSourceDir, '*', 'node_modules'));
12+
removeSync(join(Paths.e2eTemplatesDir, '*', 'node_modules'));
13+
removeSync(Paths.e2eWorkDir);
14+
removeSync(Paths.e2eWotkDirLink);

scripts/e2e.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@ const { sync: spawnSync } = require('cross-spawn');
88
const fs = require('fs-extra');
99
const path = require('path');
1010
const Paths = require('./paths');
11+
const { satisfies } = require('semver');
1112

12-
const NodeVersion = (versions => {
13-
return { major: versions[0], minor: versions[1], patch: versions[2] };
14-
})(
15-
process.versions.node
16-
.split('-')
17-
.shift()
18-
.split('.')
19-
.map(s => parseInt(s, 10))
20-
);
13+
const npmVersion = spawnSync('npm', ['-s', '--version'])
14+
.stdout.toString()
15+
.trim();
16+
const npmHasCiCommand = satisfies(npmVersion, '>=5.7.0');
17+
const npmHasPrepare = satisfies(npmVersion, '>=4.0.0');
2118

2219
function getDirectories(rootDir) {
2320
return fs.readdirSync(rootDir).filter(function(file) {
@@ -28,6 +25,13 @@ function getDirectories(rootDir) {
2825
function setupE2e() {
2926
// this will trigger the build as well (not using yarn since yarn pack is bugy)
3027
// keep on to so that the build is triggered beforehand (pack => prepublish => clean-build => build)
28+
// Except that on npm < 4.0.0 the prepare doesn't exists
29+
if (!npmHasPrepare) {
30+
spawnSync('npm', ['-s', 'run', 'build'], {
31+
cwd: Paths.rootDir,
32+
stdio: 'inherit',
33+
});
34+
}
3135
const res = spawnSync('npm', ['-s', 'pack'], { cwd: Paths.rootDir });
3236
const bundle = path.join(Paths.rootDir, res.stdout.toString().trim());
3337

@@ -53,10 +57,9 @@ function setupE2e() {
5357
// template dir, to know if we should re-install or not
5458
if (fs.existsSync(path.join(dir, 'node_modules'))) return;
5559

56-
if (NodeVersion.major >= 8) {
60+
if (npmHasCiCommand) {
5761
spawnSync('npm', ['ci'], { cwd: dir, stdio: 'inherit' });
5862
} else {
59-
// npm coming with node < 8 does not have the `ci` command
6063
spawnSync('npm', ['i'], { cwd: dir, stdio: 'inherit' });
6164
}
6265
spawnSync('npm', ['i', '-D', bundle], { cwd: dir, stdio: 'inherit' });

0 commit comments

Comments
 (0)