-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vadim Demedes
committed
Jan 21, 2018
1 parent
947f207
commit 0b3fec6
Showing
11 changed files
with
13,502 additions
and
7,592 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
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,42 @@ | ||
'use strict'; | ||
|
||
// Check if the test is being run without AVA CLI | ||
{ | ||
const path = require('path'); | ||
const chalk = require('chalk'); | ||
|
||
const isForked = typeof process.send === 'function'; | ||
if (!isForked) { | ||
const fp = path.relative('.', process.argv[1]); | ||
|
||
console.log(); | ||
console.error('Test files must be run with the AVA CLI:\n\n ' + chalk.grey.dim('$') + ' ' + chalk.cyan('ava ' + fp) + '\n'); | ||
|
||
process.exit(1); // eslint-disable-line unicorn/no-process-exit | ||
} | ||
} | ||
|
||
const run = require('./test-worker'); | ||
|
||
const opts = JSON.parse(process.argv[2]); | ||
|
||
// Adapter for simplified communication between AVA and worker | ||
const ipcMain = { | ||
send: (name, data) => { | ||
process.send({ | ||
name: `ava-${name}`, | ||
data, | ||
ava: true | ||
}); | ||
}, | ||
on: (name, listener) => process.on(name, listener), | ||
// `process.channel` was added in Node.js 7.1.0, but the channel was available | ||
// through an undocumented API as `process._channel`. | ||
ipcChannel: process.channel || process._channel | ||
}; | ||
|
||
run({ | ||
ipcMain, | ||
opts, | ||
isForked: true | ||
}); |
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
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use strict'; | ||
const EventEmitter = require('events'); | ||
const stream = require('stream'); | ||
const vm = require('vm'); | ||
const run = require('./test-worker'); | ||
|
||
// Required to prevent warnings from Node.js, because in single mode each test file | ||
// attaches its own `uncaughtException` and `unhandledRejection` listeners. | ||
process.setMaxListeners(Infinity); | ||
|
||
module.exports = opts => { | ||
// Fake child process | ||
const ps = new EventEmitter(); | ||
ps.stdout = new stream.PassThrough(); | ||
ps.stderr = new stream.PassThrough(); | ||
|
||
// Adapter for simplified communication between AVA and worker | ||
const ipcMain = new EventEmitter(); | ||
|
||
// Incoming message from AVA to worker | ||
ps.send = data => { | ||
ipcMain.emit('message', data); | ||
}; | ||
|
||
// Fake IPC channel | ||
ipcMain.ipcChannel = { | ||
ref: () => {}, | ||
unref: () => {} | ||
}; | ||
|
||
// Outgoing message from worker to AVA | ||
ipcMain.send = (name, data) => { | ||
ps.emit('message', { | ||
name: `ava-${name}`, | ||
data, | ||
ava: true | ||
}); | ||
}; | ||
|
||
// Fake `process.exit()` | ||
ipcMain.exit = code => { | ||
ps.emit('exit', code); | ||
}; | ||
|
||
setImmediate(() => { | ||
run({ | ||
ipcMain, | ||
opts, | ||
isForked: false | ||
}); | ||
}); | ||
|
||
return ps; | ||
}; |
Oops, something went wrong.