Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow reading bundle from stdin (#269)
* Allow to read bundled tests from stdin * Validate config right after merging * Factor out config validation into own module * Improve naming around ambiguous items * Consolidate option validation logic * Throw directly when config validation fails
- Loading branch information
Showing
12 changed files
with
206 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
exports.validateConfig = validateConfig; | ||
|
||
function validateConfig(config) { | ||
if (!config.driver) { | ||
throw new Error( | ||
'Specifying a `driver` is required. Mochify drivers need to be installed separately from the API or the CLI.' | ||
); | ||
} | ||
if (config.esm && config.bundle) { | ||
throw new Error('`esm` cannot be used in conjunction with `bundle`'); | ||
} | ||
if ( | ||
config.bundle && | ||
typeof config.spec === 'object' && | ||
typeof config.spec.pipe === 'function' | ||
) { | ||
throw new Error('`bundle` cannot be used when `spec` is a stream.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const { assert, refute } = require('@sinonjs/referee-sinon'); | ||
const { validateConfig } = require('./validate-config'); | ||
|
||
describe('mochify/lib/validate-config', () => { | ||
it('returns an error when esm and bundle are given', () => { | ||
assert.exception(() => { | ||
validateConfig({ | ||
driver: 'puppeteer', | ||
esm: true, | ||
bundle: 'browserify', | ||
spec: './test.js' | ||
}); | ||
}); | ||
}); | ||
|
||
it('returns an error when bundle and a stream spec are given', () => { | ||
assert.exception(() => { | ||
validateConfig({ | ||
driver: 'puppeteer', | ||
bundle: 'browserify', | ||
spec: fs.createReadStream(__filename) | ||
}); | ||
}); | ||
}); | ||
|
||
it('returns an error on an empty config', () => { | ||
assert.exception(() => validateConfig({})); | ||
}); | ||
|
||
it('returns null on a valid config', () => { | ||
refute.exception(() => { | ||
validateConfig({ | ||
bundle: 'browserify -t babelify', | ||
spec: './test.js', | ||
driver: 'puppeteer' | ||
}); | ||
}); | ||
}); | ||
}); |