Skip to content

Commit

Permalink
Merge branch 'master' into greenkeeper/mocha-5.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
axelssonHakan committed May 23, 2018
2 parents a5ba417 + a39e848 commit 15135c6
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 10 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"nyc": "11.8.0",
"precinct": "4.2.0",
"sinon": "5.0.6",
"sinon-chai": "3.0.0",
"sinon-chai": "3.1.0",
"source-map-support": "0.5.6",
"test-exclude": "4.2.1",
"yargs": "11.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/cdp/http-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require('path');
const Koa = require('koa');
const serve = require('koa-static');
const favicon = require('koa-favicon');
const transform = require('./transform');
const transform = require('../transform');

module.exports = function createHttpServer(argv) {
const app = new Koa();
Expand Down
2 changes: 1 addition & 1 deletion src/cdp/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const NYC = require('nyc');
const Mediator = require('./mediator');
const connect = require('./connect');
const utils = require('../terminal-utils');
const { ensureFilePath, getExt, getPathWithExt } = require('./file-utils');
const { ensureFilePath, getExt, getPathWithExt } = require('../file-utils');

class Runner {
constructor(argv = { chrome: { chromeFlags: [] }, client: {} }) {
Expand Down
File renamed without changes.
7 changes: 6 additions & 1 deletion src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ const Koa = require('koa');
const serve = require('koa-static');
const favicon = require('koa-favicon');
const rewrite = require('koa-rewrite');
const transform = require('./transform');
const testExclude = require('test-exclude');

module.exports = function createServer(options) {
options = Object.assign({}, { port: 9000, root: ['./'], rewrite: {} }, options);
options = Object.assign({}, { port: 9000, root: ['./'], rewrite: {}, instrument: { exclude: '**' }, transform: { exclude: '**' } }, options); //eslint-disable-line
options.instrument.testExclude = testExclude({ include: options.instrument.include, exclude: options.instrument.exclude }); //eslint-disable-line
options.transform.testExclude = testExclude({ include: options.transform.include, exclude: options.transform.exclude }); //eslint-disable-line
const app = new Koa();
app.use(favicon(path.resolve(__dirname, '../aw.png')));
Object.keys(options.rewrite).forEach(key => app.use(rewrite(key, options.rewrite[key])));
app.use(transform(options));
app.use(...options.root.map(root => serve(path.resolve(process.cwd(), root))));
return app.listen(options.port);
};
11 changes: 8 additions & 3 deletions src/cdp/transform.js → src/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ async function transformFile(filePath, argv) {
babelOpts = Object.assign({}, babelOpts, tsBabelOpts);
}
const { code, map } = babel.transform(content, babelOpts);

if (map) {
const key = getPathWithExt(filePath, 'js.map');
virtualSourceMap.set(key, map);
Expand All @@ -87,10 +88,14 @@ async function transformFile(filePath, argv) {
module.exports = function transform(argv) {
return async (ctx, next) => {
await next();
let { url } = ctx;
// We need to remove the leading slash else it will be excluded by default
const url = ctx.url.substring(1);
const shouldInstrument = argv.coverage && argv.instrument.testExclude.shouldInstrument(url);
const shouldTransform = argv.transform.testExclude.shouldInstrument(url);
if (ctx.url.length && ctx.url.startsWith('/')) {
url = ctx.url.substring(1);
}
const shouldInstrument = argv.coverage && argv.instrument && argv.instrument.testExclude.shouldInstrument(url); //eslint-disable-line
const shouldTransform = argv.transform && argv.transform.testExclude.shouldInstrument(url);

if (shouldInstrument || shouldTransform) {
const { response } = ctx;
response.body = await transformFile(url, argv);
Expand Down

0 comments on commit 15135c6

Please sign in to comment.