-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: upgrade Jest and Babel to latest versions * feat: use create-jest-runner
- Loading branch information
Showing
8 changed files
with
2,194 additions
and
1,643 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
presets: ['@babel/preset-env'], | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,3 @@ | ||
// Copied from https://github.com/jest-community/jest-runner-eslint/blob/2e2b65ef7bf698e501d6e175a210fd7f7b6bbffc/src/index.js | ||
import { createJestRunner } from 'create-jest-runner'; | ||
|
||
const throat = require('throat'); | ||
const pify = require('pify'); | ||
const workerFarm = require('worker-farm'); | ||
const path = require('path'); | ||
|
||
const TEST_WORKER_PATH = path.join(__dirname, 'runTsc.js'); | ||
|
||
class CancelRun extends Error { | ||
constructor(message) { | ||
super(message); | ||
this.name = 'CancelRun'; | ||
} | ||
} | ||
|
||
module.exports = class TscTestRunner { | ||
constructor(globalConfig) { | ||
this._globalConfig = globalConfig; | ||
} | ||
|
||
runTests(tests, watcher, onStart, onResult, onFailure) { | ||
const farm = workerFarm( | ||
{ | ||
autoStart: true, | ||
maxConcurrentCallsPerWorker: 1, | ||
maxConcurrentWorkers: this._globalConfig.maxWorkers, | ||
maxRetries: 2, // Allow for a couple of transient errors. | ||
}, | ||
TEST_WORKER_PATH | ||
); | ||
|
||
const mutex = throat(this._globalConfig.maxWorkers); | ||
const worker = pify(farm); | ||
|
||
const runTestInWorker = test => | ||
mutex(() => { | ||
if (watcher.isInterrupted()) { | ||
throw new CancelRun(); | ||
} | ||
return onStart(test).then(() => { | ||
return worker({ | ||
config: test.context.config, | ||
globalConfig: this._globalConfig, | ||
testPath: test.path, | ||
rawModuleMap: watcher.isWatchMode() | ||
? test.context.moduleMap.getRawModuleMap() | ||
: null, | ||
}); | ||
}); | ||
}); | ||
|
||
const onError = (err, test) => { | ||
return onFailure(test, err).then(() => { | ||
if (err.type === 'ProcessTerminatedError') { | ||
// eslint-disable-next-line no-console | ||
console.error( | ||
'A worker process has quit unexpectedly! ' + | ||
'Most likely this is an initialization error.' | ||
); | ||
process.exit(1); | ||
} | ||
}); | ||
}; | ||
|
||
const onInterrupt = new Promise((_, reject) => { | ||
watcher.on('change', state => { | ||
if (state.interrupted) { | ||
reject(new CancelRun()); | ||
} | ||
}); | ||
}); | ||
|
||
const runAllTests = Promise.all( | ||
tests.map(test => | ||
runTestInWorker(test) | ||
.then(testResult => onResult(test, testResult)) | ||
.catch(error => onError(error, test)) | ||
) | ||
); | ||
|
||
const cleanup = () => workerFarm.end(farm); | ||
|
||
return Promise.race([runAllTests, onInterrupt]).then(cleanup, cleanup); | ||
} | ||
}; | ||
module.exports = createJestRunner(require.resolve('./runTsc')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.