Skip to content

Commit 946fec3

Browse files
committed
Add a profile script.
1 parent 0e6db13 commit 946fec3

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

.iron-node.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
"app": {
3+
"openDevToolsDetached" : true, // DEFAULT=FALSE; opens the dev tools windows detached in an own window.
4+
"hideMainWindow" : true, // DEFAULT=FALSE; hides the main window to show dev tools only.
5+
},
6+
"workSpaceDirectory" : function(argv) { // determines the workspace directory for specific commandline applications.
7+
return __dirname
8+
}
9+
};
10+

profile.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
'use strict';
2+
3+
// iron-node does not work with forked processes
4+
// This cli command will run a single file in the current process.
5+
// Intended to be used with iron-node for profiling purposes.
6+
7+
var path = require('path');
8+
var meow = require('meow');
9+
var Promise = require('bluebird');
10+
var pkgConf = require('pkg-conf');
11+
var arrify = require('arrify');
12+
var findCacheDir = require('find-cache-dir');
13+
var uniqueTempDir = require('unique-temp-dir');
14+
var EventEmitter = require('events').EventEmitter;
15+
var CachingPrecompiler = require('./lib/caching-precompiler');
16+
var globals = require('./lib/globals');
17+
18+
// Chrome gets upset when the `this` value is non-null for these functions.
19+
globals.setTimeout = setTimeout.bind(null);
20+
globals.clearTimeout = clearTimeout.bind(null);
21+
22+
Promise.longStackTraces();
23+
var conf = pkgConf.sync('ava');
24+
25+
// Define a minimal set of options from the main CLI.
26+
var cli = meow([
27+
'usage: iron-node node_modules/ava/profile.js [options] TEST_FILE',
28+
'',
29+
'Options',
30+
' --fail-fast Stop after first test failure',
31+
' --serial, -s Run tests serially',
32+
' --require, -r Module to preload (Can be repeated)',
33+
''
34+
], {
35+
string: [
36+
'_',
37+
'require'
38+
],
39+
boolean: [
40+
'fail-fast',
41+
'verbose',
42+
'serial',
43+
'tap'
44+
],
45+
default: conf,
46+
alias: {
47+
r: 'require',
48+
s: 'serial'
49+
}
50+
});
51+
52+
if (cli.input.length !== 1) {
53+
throw new Error('no file');
54+
}
55+
56+
var file = path.resolve(cli.input[0]);
57+
var cacheDir = findCacheDir({name: 'ava', files: [file]}) || uniqueTempDir();
58+
var opts = {
59+
file: file,
60+
failFast: cli.flags.failFast,
61+
serial: cli.flags.serial,
62+
require: arrify(cli.flags.require),
63+
tty: false,
64+
cacheDir: cacheDir,
65+
precompiled: new CachingPrecompiler(cacheDir).generateHashForFile(file)
66+
};
67+
68+
var events = new EventEmitter();
69+
70+
// Mock the behavior of a parent process.
71+
process.send = function (data) {
72+
if (data && data.ava) {
73+
var name = data.name.replace(/^ava-/, '');
74+
if (events.listenerCount(name)) {
75+
events.emit(name, data.data);
76+
} else {
77+
console.log('UNHANDLED AVA EVENT: ', name, data.data);
78+
}
79+
return;
80+
}
81+
console.log('NON AVA EVENT: ', data);
82+
};
83+
84+
events.on('test', function (data) {
85+
console.log('TEST:', data.title, data.error);
86+
});
87+
88+
events.on('results', function (data) {
89+
console.log('RESULTS: ', data.stats);
90+
});
91+
92+
events.on('stats', function () {
93+
setImmediate(function () {
94+
process.emit('ava-run');
95+
});
96+
});
97+
98+
// test-worker will read process.argv[2] for options
99+
process.argv[2] = JSON.stringify(opts);
100+
process.argv.length = 3;
101+
102+
require('./lib/test-worker');

0 commit comments

Comments
 (0)