cross-os
Version:
Allow to add OS-specific scripts in your package.json!
177 lines (176 loc) • 8.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var child_process_1 = require("child_process");
var expect = require("expect.js");
var path = require("path");
process.chdir(__dirname);
var cross = path.resolve(__dirname, '../source/index.js');
var platform = process.platform;
describe('Loader', function () {
it('should fail if it\'s invoked with an invalid script', function () {
var stdout = child_process_1.execSync("node " + cross + " invalid");
expect(stdout.toString()).to.match(new RegExp("script: 'invalid' not found for the current platform: " + platform));
});
it('should fail if it\'s invoked with an invalid script, invoking with parameters', function () {
var stdout = child_process_1.execSync("node " + cross + " invalid -- First Second Third");
expect(stdout.toString()).to.match(new RegExp("script: 'invalid' not found for the current platform: " + platform));
});
it('should run the correct script on the right OS', function () {
var stdout = child_process_1.execSync("node " + cross + " first");
expect(stdout.toString()).to.match(new RegExp("hello from " + platform));
});
it('should run the correct script on the right OS and pass the parameters', function () {
var stdout = child_process_1.execSync("node " + cross + " first-with-params -- First Second Third");
expect(stdout.toString()).to.match(new RegExp("hello from " + platform + ", I have arguments: First Second Third"));
});
it('should fail silently if script for an specific OS is not found', function () {
var stdout = child_process_1.execSync("node " + cross + " second");
expect(stdout.toString().trim()).to.match(new RegExp("script: 'second' not found for the current platform: " + platform));
});
it('should fail silently if script for an specific OS is not found, invoked with parameters', function () {
var stdout = child_process_1.execSync("node " + cross + " second -- First Second Third");
expect(stdout.toString().trim()).to.match(new RegExp("script: 'second' not found for the current platform: " + platform));
});
it('should work with npm scripts directly', function (done) {
var child = child_process_1.exec('npm run third --silent');
var output = '';
child.stdout.on('data', function (buffer) {
output += buffer.toString('utf-8');
});
child.on('exit', function (code) {
expect(output.trim()).to.match(/it is working just fine/);
expect(code).to.be(0);
done();
});
});
it('should work with npm scripts directly and pass parameters', function (done) {
var child = child_process_1.exec('npm run third-with-params First Second Third --silent');
var output = '';
child.stdout.on('data', function (buffer) {
output += buffer.toString('utf-8');
});
child.on('exit', function (code) {
expect(output.trim()).to.match(/it is working just fine with arguments: First Second Third/);
expect(code).to.be(0);
done();
});
});
it('should work with npm script + cross-os directly', function (done) {
var child = child_process_1.exec('npm run fourth --silent');
var output = '';
child.stdout.on('data', function (buffer) {
output += buffer.toString('utf-8');
});
child.on('exit', function (code) {
expect(output.trim()).to.match(new RegExp("hello from " + platform));
expect(code).to.be(0);
done();
});
});
it('should work with npm script + cross-os directly and pass parameters', function (done) {
var child = child_process_1.exec('npm run fourth-with-params --silent -- First Second Third');
var output = '';
child.stdout.on('data', function (buffer) {
output += buffer.toString('utf-8');
});
child.on('exit', function (code) {
expect(output.trim()).to.match(new RegExp("hello from " + platform + ", I have arguments: First Second Third"));
expect(code).to.be(0);
done();
});
});
it('should run scripts defined in cross-os attributes', function () {
var stdout = child_process_1.execSync("node " + cross + " fifth");
expect(stdout.toString()).to.match(new RegExp("hello from cross-os " + platform));
});
it('should run scripts defined in cross-os attributes and pass parameters', function () {
var stdout = child_process_1.execSync("node " + cross + " fifth-with-params -- First Second Third");
expect(stdout.toString()).to.match(new RegExp("hello from cross-os " + platform + ", I have arguments: First Second Third"));
});
it('should run scripts defined in cross-os attributes (called from npm scripts)', function (done) {
var child = child_process_1.exec('npm run seventh --silent');
var output = '';
child.stdout.on('data', function (buffer) {
output += buffer.toString('utf-8');
});
child.on('exit', function (code) {
expect(output.trim()).to.match(new RegExp("hello from cross-os " + platform));
expect(code).to.be(0);
done();
});
});
it('should run scripts defined in cross-os attributes (called from npm scripts) and pass parameters', function (done) {
var child = child_process_1.exec('npm run seventh-with-params --silent -- First Second Third');
var output = '';
child.stdout.on('data', function (buffer) {
output += buffer.toString('utf-8');
});
child.on('exit', function (code) {
expect(output.trim()).to.match(new RegExp("hello from cross-os " + platform + ", I have arguments: First Second Third"));
expect(code).to.be(0);
done();
});
});
it('scripts should have precedence over cross-os attribute', function (done) {
var child = child_process_1.exec('npm run sixth --silent');
var output = '';
child.stdout.on('data', function (buffer) {
output += buffer.toString('utf-8');
});
child.on('exit', function (code) {
expect(output.trim()).to.match(new RegExp("hello from " + platform));
expect(code).to.be(0);
done();
});
});
it('scripts should have precedence over cross-os attribute and pass parameters', function (done) {
var child = child_process_1.exec('npm run sixth-with-params --silent -- First Second Third');
var output = '';
child.stdout.on('data', function (buffer) {
output += buffer.toString('utf-8');
});
child.on('exit', function (code) {
expect(output.trim()).to.match(new RegExp("hello from " + platform + ", I have arguments: First Second Third"));
expect(code).to.be(0);
done();
});
});
it('should not conflict with script containing the same name as its callee', function (done) {
var child = child_process_1.exec('npm run foo --silent');
var output = '';
child.stdout.on('data', function (buffer) {
output += buffer.toString('utf-8');
});
child.on('exit', function (code) {
expect(output.trim()).to.match(/bar/);
expect(code).to.be(0);
done();
});
});
it('should not conflict with script containing the same name as its callee and pass parameters', function (done) {
var child = child_process_1.exec('npm run foo-with-params --silent -- First Second Third');
var output = '';
child.stdout.on('data', function (buffer) {
output += buffer.toString('utf-8');
});
child.on('exit', function (code) {
expect(output.trim()).to.match(new RegExp("bar from " + platform + ", I have arguments: First Second Third"));
expect(code).to.be(0);
done();
});
});
it('should fail if child fails', function (done) {
var child = child_process_1.exec("node " + cross + " fail");
child.on('exit', function (code) {
expect(code).to.be(1);
done();
});
});
it('should fail if child fails when passing parameters', function (done) {
var child = child_process_1.exec("node " + cross + " fail-with-params");
child.on('exit', function (code) {
expect(code).to.be(1);
done();
});
});
});