diff --git a/.travis.yml b/.travis.yml index d419db4b39..7a97eef2d7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,10 +10,5 @@ node_js: - "6" before_install: - sudo sysctl fs.inotify.max_user_watches=524288 - - npm i -g greenkeeper-lockfile@1 rimraf -before_script: - # - greenkeeper-lockfile-update script: - npm test -after_script: - # - greenkeeper-lockfile-upload diff --git a/appveyor.yml b/appveyor.yml index 0789790064..6dafb7f0e7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -23,7 +23,6 @@ install: - ps: Install-Product node $env:nodejs_version - set CI=true - set AppVeyor=true - - npm i -g rimraf - npm ci || npm install build: off diff --git a/e2e/__helpers__/test-case.ts b/e2e/__helpers__/test-case.ts index 84196efff9..a0d8151d53 100644 --- a/e2e/__helpers__/test-case.ts +++ b/e2e/__helpers__/test-case.ts @@ -130,24 +130,25 @@ export default function configureTestCase( } export function sanitizeOutput(output: string): string { - return ( - output - .trim() - // removes total and estimated times - .replace( - /^(\s*Time\s*:\s*)[\d.]+m?s(?:(,\s*estimated\s+)[\d.]+m?s)?(\s*)$/gm, - (_, start, estimatedPrefix, end) => { - return `${start}XXs${ - estimatedPrefix ? `${estimatedPrefix}YYs` : '' - }${end}`; - }, - ) - // removes each test time values - .replace( - /^(\s*(?:✕|✓)\s+.+\s+\()[\d.]+m?s(\)\s*)$/gm, - (_, start, end) => `${start}XXms${end}`, - ) - ); + let out: string = output + .trim() + // removes total and estimated times + .replace( + /^(\s*Time\s*:\s*)[\d.]+m?s(?:(,\s*estimated\s+)[\d.]+m?s)?(\s*)$/gm, + (_, start, estimatedPrefix, end) => { + return `${start}XXs${end}`; + }, + ) + // removes each test time values + .replace( + /^(\s*(?:✕|×|✓|√)\s+.+\s+\()[\d.]+m?s(\)\s*)$/gm, + (_, start, end) => `${start}XXms${end}`, + ); + // TODO: improves this... + if (process.platform === 'win32') { + out = out.replace(/\\/g, '/'); + } + return out; } export function run( diff --git a/e2e/__tests__/__snapshots__/source-map.spec.ts.snap b/e2e/__tests__/__snapshots__/source-map.spec.ts.snap index 90ea494b91..b00c5d23a0 100644 --- a/e2e/__tests__/__snapshots__/source-map.spec.ts.snap +++ b/e2e/__tests__/__snapshots__/source-map.spec.ts.snap @@ -32,7 +32,7 @@ Object { Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total - Time: XXs, estimated YYs + Time: XXs Ran all test suites. ================================================================================, "with-babel-7": jest exit code: 1 @@ -65,7 +65,7 @@ Object { Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total - Time: XXs, estimated YYs + Time: XXs Ran all test suites. ================================================================================, "with-jest-22": jest exit code: 1 @@ -97,7 +97,7 @@ Object { Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total - Time: XXs, estimated YYs + Time: XXs Ran all test suites. ================================================================================, } diff --git a/package.json b/package.json index e3735ef751..c06549d75a 100644 --- a/package.json +++ b/package.json @@ -5,14 +5,15 @@ "types": "./dist/index.d.ts", "description": "A preprocessor with sourcemap support to help use Typescript with Jest", "scripts": { + "prebuild": "node scripts/clean-dist.js", "build": "tsc -p tsconfig.build.json", "build:watch": "tsc -p tsconfig.build.json -w", "clean": "node scripts/clean.js", - "pretest": "npm run tslint", + "pretest": "npm run lint", "test": "node scripts/e2e.js", - "tslint": "tslint 'src/**/*.ts'", + "lint": "tslint 'src/**/*.ts'", "doc": "doctoc .", - "prepare": "rimraf dist && npm run build", + "prepare": "npm run build", "prepublishOnly": "npm run test", "precommit": "lint-staged", "postcommit": "git reset", @@ -54,7 +55,7 @@ "lint-staged": "^7.2.0", "prettier": "^1.14.1", "reflect-metadata": "^0.1.12", - "rimraf": "^2.6.2", + "semver": "^5.5.0", "tslint": "^5.11.0", "typescript": "^2.9.2" }, diff --git a/scripts/clean-dist.js b/scripts/clean-dist.js new file mode 100644 index 0000000000..7727e6d5b4 --- /dev/null +++ b/scripts/clean-dist.js @@ -0,0 +1,6 @@ +#!/usr/bin/env node + +const { removeSync } = require('fs-extra'); +const Paths = require('./paths'); + +removeSync(Paths.distDir); diff --git a/scripts/clean.js b/scripts/clean.js index e015cf157f..ffcada56de 100755 --- a/scripts/clean.js +++ b/scripts/clean.js @@ -1,14 +1,14 @@ #!/usr/bin/env node -const rimraf = require('rimraf'); +const { removeSync } = require('fs-extra'); const Paths = require('./paths'); const { join } = require('path'); -rimraf.sync(Paths.distDir); -rimraf.sync(join(Paths.testsRootDir, '*', 'coverage')); -rimraf.sync(join(Paths.testsRootDir, '*', 'debug.txt')); -rimraf.sync(join(Paths.testsRootDir, '*', 'node_modules')); -rimraf.sync(join(Paths.e2eSourceDir, '*', 'node_modules')); -rimraf.sync(join(Paths.e2eTemplatesDir, '*', 'node_modules')); -rimraf.sync(Paths.e2eWorkDir); -rimraf.sync(Paths.e2eWotkDirLink); +removeSync(Paths.distDir); +removeSync(join(Paths.testsRootDir, '*', 'coverage')); +removeSync(join(Paths.testsRootDir, '*', 'debug.txt')); +removeSync(join(Paths.testsRootDir, '*', 'node_modules')); +removeSync(join(Paths.e2eSourceDir, '*', 'node_modules')); +removeSync(join(Paths.e2eTemplatesDir, '*', 'node_modules')); +removeSync(Paths.e2eWorkDir); +removeSync(Paths.e2eWotkDirLink); diff --git a/scripts/e2e.js b/scripts/e2e.js index ae1eb97196..5ab3ed83db 100755 --- a/scripts/e2e.js +++ b/scripts/e2e.js @@ -8,16 +8,13 @@ const { sync: spawnSync } = require('cross-spawn'); const fs = require('fs-extra'); const path = require('path'); const Paths = require('./paths'); +const { satisfies } = require('semver'); -const NodeVersion = (versions => { - return { major: versions[0], minor: versions[1], patch: versions[2] }; -})( - process.versions.node - .split('-') - .shift() - .split('.') - .map(s => parseInt(s, 10)) -); +const npmVersion = spawnSync('npm', ['-s', '--version']) + .stdout.toString() + .trim(); +const npmHasCiCommand = satisfies(npmVersion, '>=5.7.0'); +const npmHasPrepare = satisfies(npmVersion, '>=4.0.0'); function getDirectories(rootDir) { return fs.readdirSync(rootDir).filter(function(file) { @@ -28,6 +25,13 @@ function getDirectories(rootDir) { function setupE2e() { // this will trigger the build as well (not using yarn since yarn pack is bugy) // keep on to so that the build is triggered beforehand (pack => prepublish => clean-build => build) + // Except that on npm < 4.0.0 the prepare doesn't exists + if (!npmHasPrepare) { + spawnSync('npm', ['-s', 'run', 'build'], { + cwd: Paths.rootDir, + stdio: 'inherit', + }); + } const res = spawnSync('npm', ['-s', 'pack'], { cwd: Paths.rootDir }); const bundle = path.join(Paths.rootDir, res.stdout.toString().trim()); @@ -53,10 +57,9 @@ function setupE2e() { // template dir, to know if we should re-install or not if (fs.existsSync(path.join(dir, 'node_modules'))) return; - if (NodeVersion.major >= 8) { + if (npmHasCiCommand) { spawnSync('npm', ['ci'], { cwd: dir, stdio: 'inherit' }); } else { - // npm coming with node < 8 does not have the `ci` command spawnSync('npm', ['i'], { cwd: dir, stdio: 'inherit' }); } spawnSync('npm', ['i', '-D', bundle], { cwd: dir, stdio: 'inherit' });