Skip to content

Commit

Permalink
Add support for --skip-node and --skip-browser options to build-test …
Browse files Browse the repository at this point in the history
…command
  • Loading branch information
Giancarlo Anemone authored and rtsao committed Jan 31, 2018
1 parent ed200d8 commit 4065a15
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 3 deletions.
9 changes: 7 additions & 2 deletions packages/create-universal-package/bin/build-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
const args = require('args');
args
.option('dir', 'Path to package dir', process.cwd())
.option('skip-coverage', 'Skip coverage instrumentation', false);
.option('skip-coverage', 'Skip coverage instrumentation', false)
.option('skip-browser', 'Exclude browser build', false)
.option('skip-node', 'Exclude node build', false);

const flags = args.parse(process.argv);

const build = require('../lib/build.js');
const jobs = build(flags, {testBrowser: true, testNode: true});
const jobs = build(flags, {
testBrowser: !flags.skipBrowser,
testNode: !flags.skipNode,
});

const logger = process.stdout.isTTY
? require('./logger.js')
Expand Down
2 changes: 1 addition & 1 deletion packages/create-universal-package/bin/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ args.option('dir', 'Path to package dir', process.cwd());

const flags = args.parse(process.argv);

const clean = require('../lib/clean.js');
const clean = require('../lib/tasks/clean.js');
clean(flags);
11 changes: 11 additions & 0 deletions packages/create-universal-package/lib/tasks/clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const cp = require('child_process');
const {promisify} = require('util');
const exec = promisify(cp.exec);
const path = require('path');

module.exports = function clean(opts) {
return Promise.all([
exec(`rm -rf ${path.join(opts.dir, 'dist-tests/')}`),
exec(`rm -rf ${path.join(opts.dir, 'dist/')}`),
]);
};
55 changes: 55 additions & 0 deletions packages/create-universal-package/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const exec = promisify(cp.exec);

tape('fixture package transpile', async t => {
const dir = path.join(__dirname, '../../fixture-package/');
await exec(`yarn clean`, {cwd: dir});
await exec(`yarn build`, {cwd: dir});
const expectedFiles = [
'browser.es2015.es.js',
Expand All @@ -31,8 +32,62 @@ tape('fixture package transpile', async t => {
t.end();
});

tape('fixture package build-tests', async t => {
const dir = path.join(__dirname, '../../fixture-package/');
await exec(`yarn clean`, {cwd: dir});
await exec(`yarn pretest`, {cwd: dir});
const expectedFiles = ['browser.js', 'node.js', 'node.js.map'];
expectedFiles
.map(file => path.join(dir, 'dist-tests', file))
.forEach((file, index) => {
t.ok(fs.existsSync(file), `${expectedFiles[index]} exists`);
});
t.end();
});

tape('fixture package build-tests --skip-browser', async t => {
const dir = path.join(__dirname, '../../fixture-package/');
await exec(`yarn clean`, {cwd: dir});
await exec(`yarn pretest --skip-browser`, {cwd: dir});
const expectedFiles = ['node.js', 'node.js.map'];
const nonExpectedFiles = ['browser.js'];
expectedFiles
.map(file => path.join(dir, 'dist-tests', file))
.forEach((file, index) => {
t.ok(fs.existsSync(file), `${expectedFiles[index]} exists`);
});

nonExpectedFiles
.map(file => path.join(dir, 'dist-tests', file))
.forEach((file, index) => {
t.notok(fs.existsSync(file), `${nonExpectedFiles[index]} does not exist`);
});
t.end();
});

tape('fixture package build-tests --skip-node', async t => {
const dir = path.join(__dirname, '../../fixture-package/');
await exec(`yarn clean`, {cwd: dir});
await exec(`yarn pretest --skip-node`, {cwd: dir});
const expectedFiles = ['browser.js'];
const nonExpectedFiles = ['node.js', 'node.js.map'];
expectedFiles
.map(file => path.join(dir, 'dist-tests', file))
.forEach((file, index) => {
t.ok(fs.existsSync(file), `${expectedFiles[index]} exists`);
});

nonExpectedFiles
.map(file => path.join(dir, 'dist-tests', file))
.forEach((file, index) => {
t.notok(fs.existsSync(file), `${nonExpectedFiles[index]} does not exist`);
});
t.end();
});

tape('fixture package separate indexes transpile', async t => {
const dir = path.join(__dirname, '../../fixture-package-separate-indexes/');
await exec(`yarn clean`, {cwd: dir});
await exec(`yarn build`, {cwd: dir});
const expectedFiles = [
'browser.es2015.es.js',
Expand Down

0 comments on commit 4065a15

Please sign in to comment.