Skip to content
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

Implement preprocess option in the testling field #62

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
22 changes: 20 additions & 2 deletions bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,27 @@ if ((process.stdin.isTTY || argv._.length) && argv._[0] !== '-') {
scripts = expanded.script;

if (expanded.file.length) {
var args = expanded.file.concat('--debug');
var spawnOpts = { cwd: dir, env: env };
var ps;

if (pkg.testling.preprocess) {
var cmd, ags;

if (typeof pkg.testling.preprocess === 'string') {
cmd = parseCommand(pkg.testling.preprocess);
args = cmd.slice(1);
cmd = cmd[0];
} else {
cmd = pkg.testling.preprocess.command;
args = pkg.testling.preprocess.args;
}

ps = spawn(cmd, args, spawnOpts);
} else {
var args = expanded.file.concat('--debug');
ps = spawn('browserify', args, spawnOpts);
}

var ps = spawn('browserify', args, { cwd: dir, env: env });
ps.stdout.pipe(concat(function (src) {
bundle = src;
htmlQueue.forEach(function (f) { getHTML(f) });
Expand Down
33 changes: 33 additions & 0 deletions readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,39 @@ The exit code of coverify is non-zero when there are unreachable expressions.

Make sure you have [PhantomJS](https://github.com/ariya/phantomjs) installed; this is the headless browser that testling will run your tests in if you are not using the `-u` option.

# custom preprocess command

Its possible to configure testling to run a custom bundle command instead of
the default(browserify --debug). A simple use case is to prepend shims for
testing a library in older browsers.

For example, lets say you have created a library that uses ES5 features but
needs to be tested in IE7. To test this library correctly the shims need to be
prepended in the browserified bundle, which can be achieved doing something
like this:

```sh
npm install --save-dev es5-shim json3
```

Then configure the "preprocess" option:

```json
{
"testling": {
"preprocess": {
"command": "bash",
"args": [
"-c",
"browserify test/*.js | cat node_modules/json3/lib/json3.js node_modules/es5-shim/es5-sh{im,am}.js -"
]
},
}
}
```

The above runs browserify and prepend shims to the bundle served by testling.

# install

First, install `browserify` globally so that the `testling` command can find it
Expand Down