Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.

Commit 33345d3

Browse files
authored
feat: enable transform in protractor (#220)
* feat: enable transform in protractor * chore: safe check option * chore: fix lint
1 parent 05d33ee commit 33345d3

5 files changed

Lines changed: 16 additions & 6 deletions

File tree

src/cdp/http-server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const path = require('path');
22
const Koa = require('koa');
33
const serve = require('koa-static');
44
const favicon = require('koa-favicon');
5-
const transform = require('./transform');
5+
const transform = require('../transform');
66

77
module.exports = function createHttpServer(argv) {
88
const app = new Koa();

src/cdp/runner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const NYC = require('nyc');
1212
const Mediator = require('./mediator');
1313
const connect = require('./connect');
1414
const utils = require('../terminal-utils');
15-
const { ensureFilePath, getExt, getPathWithExt } = require('./file-utils');
15+
const { ensureFilePath, getExt, getPathWithExt } = require('../file-utils');
1616

1717
class Runner {
1818
constructor(argv = { chrome: { chromeFlags: [] }, client: {} }) {
File renamed without changes.

src/server.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ const Koa = require('koa');
33
const serve = require('koa-static');
44
const favicon = require('koa-favicon');
55
const rewrite = require('koa-rewrite');
6+
const transform = require('./transform');
7+
const testExclude = require('test-exclude');
68

79
module.exports = function createServer(options) {
8-
options = Object.assign({}, { port: 9000, root: ['./'], rewrite: {} }, options);
10+
options = Object.assign({}, { port: 9000, root: ['./'], rewrite: {}, instrument: { exclude: '**' }, transform: { exclude: '**' } }, options); //eslint-disable-line
11+
options.instrument.testExclude = testExclude({ include: options.instrument.include, exclude: options.instrument.exclude }); //eslint-disable-line
12+
options.transform.testExclude = testExclude({ include: options.transform.include, exclude: options.transform.exclude }); //eslint-disable-line
913
const app = new Koa();
1014
app.use(favicon(path.resolve(__dirname, '../aw.png')));
1115
Object.keys(options.rewrite).forEach(key => app.use(rewrite(key, options.rewrite[key])));
16+
app.use(transform(options));
1217
app.use(...options.root.map(root => serve(path.resolve(process.cwd(), root))));
1318
return app.listen(options.port);
1419
};
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ async function transformFile(filePath, argv) {
7777
babelOpts = Object.assign({}, babelOpts, tsBabelOpts);
7878
}
7979
const { code, map } = babel.transform(content, babelOpts);
80+
8081
if (map) {
8182
const key = getPathWithExt(filePath, 'js.map');
8283
virtualSourceMap.set(key, map);
@@ -87,10 +88,14 @@ async function transformFile(filePath, argv) {
8788
module.exports = function transform(argv) {
8889
return async (ctx, next) => {
8990
await next();
91+
let { url } = ctx;
9092
// We need to remove the leading slash else it will be excluded by default
91-
const url = ctx.url.substring(1);
92-
const shouldInstrument = argv.coverage && argv.instrument.testExclude.shouldInstrument(url);
93-
const shouldTransform = argv.transform.testExclude.shouldInstrument(url);
93+
if (ctx.url.length && ctx.url.startsWith('/')) {
94+
url = ctx.url.substring(1);
95+
}
96+
const shouldInstrument = argv.coverage && argv.instrument && argv.instrument.testExclude.shouldInstrument(url); //eslint-disable-line
97+
const shouldTransform = argv.transform && argv.transform.testExclude.shouldInstrument(url);
98+
9499
if (shouldInstrument || shouldTransform) {
95100
const { response } = ctx;
96101
response.body = await transformFile(url, argv);

0 commit comments

Comments
 (0)