Skip to content

Add a profile script #475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .iron-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
"app": {
"openDevToolsDetached" : true, // DEFAULT=FALSE; opens the dev tools windows detached in an own window.
"hideMainWindow" : true, // DEFAULT=FALSE; hides the main window to show dev tools only.
},
"workSpaceDirectory" : function(argv) { // determines the workspace directory for specific commandline applications.
return __dirname
}
};

102 changes: 102 additions & 0 deletions profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
'use strict';

// iron-node does not work with forked processes
// This cli command will run a single file in the current process.
// Intended to be used with iron-node for profiling purposes.

var path = require('path');
var meow = require('meow');
var Promise = require('bluebird');
var pkgConf = require('pkg-conf');
var arrify = require('arrify');
var findCacheDir = require('find-cache-dir');
var uniqueTempDir = require('unique-temp-dir');
var EventEmitter = require('events').EventEmitter;
var CachingPrecompiler = require('./lib/caching-precompiler');
var globals = require('./lib/globals');

// Chrome gets upset when the `this` value is non-null for these functions.
globals.setTimeout = setTimeout.bind(null);
globals.clearTimeout = clearTimeout.bind(null);

Promise.longStackTraces();
var conf = pkgConf.sync('ava');

// Define a minimal set of options from the main CLI.
var cli = meow([
'usage: iron-node node_modules/ava/profile.js [options] TEST_FILE',
'',
'Options',
' --fail-fast Stop after first test failure',
' --serial, -s Run tests serially',
' --require, -r Module to preload (Can be repeated)',
''
], {
string: [
'_',
'require'
],
boolean: [
'fail-fast',
'verbose',
'serial',
'tap'
],
default: conf,
alias: {
r: 'require',
s: 'serial'
}
});

if (cli.input.length !== 1) {
throw new Error('no file');
}

var file = path.resolve(cli.input[0]);
var cacheDir = findCacheDir({name: 'ava', files: [file]}) || uniqueTempDir();
var opts = {
file: file,
failFast: cli.flags.failFast,
serial: cli.flags.serial,
require: arrify(cli.flags.require),
tty: false,
cacheDir: cacheDir,
precompiled: new CachingPrecompiler(cacheDir).generateHashForFile(file)
};

var events = new EventEmitter();

// Mock the behavior of a parent process.
process.send = function (data) {
if (data && data.ava) {
var name = data.name.replace(/^ava-/, '');
if (events.listenerCount(name)) {
events.emit(name, data.data);
} else {
console.log('UNHANDLED AVA EVENT: ', name, data.data);
}
return;
}
console.log('NON AVA EVENT: ', data);
};

events.on('test', function (data) {
console.log('TEST:', data.title, data.error);
});

events.on('results', function (data) {
console.log('RESULTS: ', data.stats);
});

events.on('stats', function () {
setImmediate(function () {
process.emit('ava-run');
});
});

// test-worker will read process.argv[2] for options
process.argv[2] = JSON.stringify(opts);
process.argv.length = 3;

require('./lib/test-worker');