Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: esbuild #141

Merged
merged 36 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b019f23
feat: esbuild
hugomrdias Jan 29, 2021
1d47ba1
feat: it works
hugomrdias Feb 1, 2021
fea1ff3
fix: lint
hugomrdias Feb 1, 2021
3c0c5cd
feat: uncaught exceptions and ts support
hugomrdias Feb 2, 2021
95191dd
fix: input and process.env
hugomrdias Feb 3, 2021
1b7e440
chore: increase timeout
hugomrdias Feb 3, 2021
d4283ed
fix: support config file and filter mocha options
hugomrdias Feb 4, 2021
2647afc
docs: update docs
hugomrdias Feb 4, 2021
3d3044b
chore: before docs
hugomrdias Feb 4, 2021
44a5276
fix: remove buffer
hugomrdias Feb 4, 2021
19195f2
fix: skip another error
hugomrdias Feb 4, 2021
5e5faa8
fix: only download one browser
hugomrdias Feb 6, 2021
7fbea76
fix: deps
hugomrdias Feb 6, 2021
d0a7aa2
fix: fix tape
hugomrdias Feb 6, 2021
fc2d098
fix: tape
hugomrdias Feb 6, 2021
73c988f
fix: reduce ci
hugomrdias Feb 6, 2021
53d97a4
fix: fix windows path
hugomrdias Feb 6, 2021
e2cdc33
fix: fix windows path 1
hugomrdias Feb 6, 2021
2ba1ca7
fix: fix windows path 1
hugomrdias Feb 6, 2021
17a9eb8
fix: fix windows path 2
hugomrdias Feb 6, 2021
a30f0ff
fix: fix windows path 3
hugomrdias Feb 6, 2021
be37b98
fix: fix windows path 4
hugomrdias Feb 6, 2021
b1d8525
fix: test pw browser path
hugomrdias Feb 6, 2021
045d641
fix: remove comments and console.log
hugomrdias Feb 6, 2021
26d75c4
fix: add grep back
hugomrdias Feb 6, 2021
0d90497
fix: harden server
hugomrdias Feb 6, 2021
03959ad
fix: use a diferent folder for browser
hugomrdias Feb 8, 2021
8dfb73b
feat: improve server, logger
hugomrdias Feb 10, 2021
c2d2045
fix: remove deps
hugomrdias Feb 10, 2021
3769786
fix: update deps
hugomrdias Feb 11, 2021
66b81cd
fix: global
hugomrdias Feb 11, 2021
47bc124
fix: error and uncaught exception
hugomrdias Feb 12, 2021
560cc5e
fix: deps
hugomrdias Feb 12, 2021
b7f301b
fix: improve cov exclude
hugomrdias Feb 12, 2021
0089af4
fix: update esbuild
hugomrdias Feb 15, 2021
5cde5c1
docs: update docs
hugomrdias Feb 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 7 additions & 31 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,31 @@ jobs:
linux:
name: "Linux"
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
node: [14]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- uses: microsoft/playwright-github-action@v1
- run: yarn
- run: yarn lint
- run: xvfb-run -a yarn test
- run: npm install
- run: npm run lint
- run: xvfb-run -a npm run test
- run: ./cli.js mocks/test.mocha.js --browser firefox
- run: ./cli.js mocks/test.mocha.js --browser webkit

macos:
name: "Mac"
runs-on: macos-latest
strategy:
fail-fast: true
matrix:
node: [12, 14]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: yarn
- run: yarn test
- run: npm install
- run: npm test
- run: ./cli.js mocks/test.mocha.js --browser firefox
- run: ./cli.js mocks/test.mocha.js --browser webkit

win:
name: "Win"
runs-on: windows-latest
strategy:
fail-fast: true
matrix:
node: [12, 14]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: yarn
- run: yarn test
shell: bash
- run: npm install
- run: npm test
- run: ./cli.js mocks/test.mocha.js --browser firefox
shell: bash
- run: ./cli.js mocks/test.mocha.js --browser webkit
shell: bash
36 changes: 30 additions & 6 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

'use strict';

const path = require('path');
const sade = require('sade');
const kleur = require('kleur');
const lilconfig = require('lilconfig');
Expand All @@ -15,6 +16,18 @@ const TapeRunner = require('./src/runner-tape');
const BenchmarkRunner = require('./src/runner-benchmark');
const ZoraRunner = require('./src/runner-zora');

// Handle any uncaught errors
process.once('uncaughtException', (err, origin) => {
if (!origin || origin === 'uncaughtException') {
console.error(err);
process.exit(1);
}
});
process.once('unhandledRejection', (err) => {
console.error(err);
process.exit(1);
});

const extra = `
${kleur.bold('Examples')}
${kleur.dim('$ playwright-test test.js --runner tape')}
Expand Down Expand Up @@ -76,13 +89,23 @@ sade2
.option('-w, --watch', 'Watch files for changes and re-run tests.')
.option('-i, --incognito', 'Use incognito window to run tests.')
.option('-e, --extension', 'Use extension background_page to run tests.')
.option('--cov', 'Enable code coverage in istanbul format. Outputs \'.nyc_output/out.json\'.')
.option('--before', 'Full path to a script to be loaded on a separate tab before the main script.')
.option('--cov', 'Enable code coverage in istanbul format. Outputs \'.nyc_output/coverage-pw.json\'.')
.option('--before', 'Path to a script to be loaded on a separate tab before the main script.')
.option('--assets', 'Assets to be served by the http server. (default process.cwd())')
.option('--cwd', 'Current directory. (default process.cwd())')
.option('--extensions', 'File extensions allowed in the bundle. (default js,cjs,mjs)')
.option('--extensions', 'File extensions allowed in the bundle. (default js,cjs,mjs,ts,tsx)')
.option('--config', 'Path to the config file')
.action((input, opts) => {
const config = lilconfig.lilconfigSync('playwright-test').search();
let config;

if (opts.config) {
config = lilconfig.lilconfigSync('playwright-test').load(path.resolve(opts.config));
} else {
config = lilconfig.lilconfigSync('playwright-test').search();
if (!config) {
config = lilconfig.lilconfigSync('pw-test').search();
}
}

let Runner = null;

Expand Down Expand Up @@ -115,12 +138,13 @@ sade2
debug: opts.debug,
mode: opts.mode,
incognito: opts.incognito,
input,
input: [input, ...opts._],
extension: opts.extension,
runnerOptions: runnerOptions(opts),
before: opts.before,
node: opts.node,
cov: opts.cov
cov: opts.cov,
extensions: opts.extensions
}
));

Expand Down
11 changes: 11 additions & 0 deletions mocks/lib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import delay from 'delay'

export const good = async () => {
await delay(100)
return 'good'
}

export const bad = async () => {
await delay(100)
return 'bad'
}
12 changes: 10 additions & 2 deletions mocks/test.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// eslint-disable-next-line strict
const assert = require('assert');
const debug = require('debug')('app');
const { good, bad } = require('./lib');

describe('Array', () => {
describe('#indexOf()', () => {
Expand All @@ -10,13 +11,20 @@ describe('Array', () => {
});

it('should fail ', () => {
// console.log(chrome);
assert.equal([1, 2, 3].indexOf(2), 1);
assert.strictEqual([1, 2, 3].indexOf(2), 1);
});

it('should pass with debug', () => {
assert.equal([1, 2, 3].indexOf(4), -1);
debug('test pass');
});

it('should return "good"', async () => {
assert.strictEqual(await good(), 'good');
});

it('should return "bad"', async () => {
assert.strictEqual(await bad(), 'bad');
});
});
});
6 changes: 3 additions & 3 deletions mocks/test2.zora.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
// 'use strict';

const { test, only } = require('zora');
// import {test, only} from 'zora';
// const { test, only } = require('zora');
import {test, only} from 'zora';

test('some grouped assertions', (t) => {
t.ok(true, 'true is truthy');
Expand Down
2 changes: 1 addition & 1 deletion mocks/uvu/test1.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test('sum', () => {
});

test('sum', async () => {
await delay(2000);
await delay(100);
assert.type(() => {}, 'function');
assert.is(3, 3);
});
Expand Down
50 changes: 16 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,61 +41,42 @@
],
"dependencies": {
"camelcase": "^6.2.0",
"delay": "^4.4.0",
"get-port": "^5.1.1",
"delay": "^5.0.0",
"esbuild": "^0.8.46",
"globby": "^11.0.2",
"kleur": "^4.1.4",
"lilconfig": "^2.0.2",
"lodash": "^4.17.20",
"merge-options": "^3.0.4",
"ora": "^5.3.0",
"p-each-series": "^2.2.0",
"playwright-core": "1.8.0",
"path-browserify": "^1.0.1",
"playwright-core": "1.8.1",
"polka": "^0.5.2",
"resolve-cwd": "^3.0.0",
"premove": "^3.0.1",
"process": "^0.11.10",
"sade": "^1.7.4",
"sirv": "^1.0.10",
"sirv": "^1.0.11",
"source-map": "^0.6.0",
"strip-ansi": "^6.0.0",
"tempy": "^1.0.0",
"v8-to-istanbul": "^7.1.0",
"webpack": "^4.42.1",
"webpack-merge": "^4.2.2"
"test-exclude": "^6.0.0",
"v8-to-istanbul": "^7.1.0"
},
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"assert": "^2.0.0",
"benchmark": "^2.1.4",
"debug": "^4.3.1",
"eslint": "^4.7.1",
"eslint-config-halo": "^2.3.3",
"esm": "^3.2.25",
"execa": "^5.0.0",
"husky": "^4.3.8",
"fresh-tape": "^5.1.1",
"lint-staged": "^10.5.3",
"mocha": "^8.2.1",
"np": "^7.2.0",
"np": "^7.3.0",
"tap-spec": "^5.0.0",
"tape": "^5.1.1",
"uvu": "^0.5.1",
"zora": "^4.0.2"
},
"husky": {
"hooks": {
"pre-commit": "yarn test && lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"lint-staged": {
"*.js": [
"eslint --fix"
]
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"eslintConfig": {
"extends": "halo/plugins",
"parserOptions": {
Expand All @@ -106,8 +87,9 @@
"node_modules",
"coverage",
"dist",
"storybook-static",
"typings",
"src/benchmark.js"
"src/vendor/benchmark.js",
"src/vendor/source-map-support.js",
"node-globals.js",
"mocks"
]
}
22 changes: 19 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ Description
-w, --watch Watch files for changes and re-run tests.
-i, --incognito Use incognito window to run tests.
-e, --extension Use extension background_page to run tests.
--cov Enable code coverage in istanbul format. Outputs '.nyc_output/out.json'.
--before Full path to a script to be loaded on a separate tab before the main script.
--cov Enable code coverage in istanbul format. Outputs '.nyc_output/coverage-pw.json'.
--before Path to a script to be loaded on a separate tab before the main script.
--assets Assets to be served by the http server. (default process.cwd())
--cwd Current directory. (default process.cwd())
--extensions File extensions allowed in the bundle. (default js,cjs,mjs)
--extensions File extensions allowed in the bundle. (default js,cjs,mjs,ts,tsx)
--config Path to the config file
-v, --version Displays current version
-h, --help Displays this message

Expand Down Expand Up @@ -72,6 +73,21 @@ Description
$ playwright-test "test/**" GOOD
$ playwright-test test/** BAD
```
## Config
Configuration can be done with cli flags or config files.
```js
'package.json', // using property `pw-test` or `playwright-test`
`.playwright-testrc.json`,
`.playwright-testrc.js`,
`playwright-test.config.js`,
`.playwright-testrc.cjs`,
`playwright-test.config.cjs`,
`.pw-testrc.json`,
`.pw-testrc.js`,
`pw-test.config.js`,
`.pw-testrc.cjs`,
`pw-test.config.cjs`,
```

## Run in CI
Check our CI config `.github/workflows/main.yml` and the playwright Github Action https://playwright.dev/#version=v1.5.2&path=docs%2Fci.md&q=github-actions
Expand Down
2 changes: 2 additions & 0 deletions src/node-globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const process = require('process/browser')
// https://github.com/ionic-team/rollup-plugin-node-polyfills
23 changes: 9 additions & 14 deletions src/runner-benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,21 @@
'use strict';

const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const Runner = require('./runner');
const { defaultWebpackConfig } = require('./utils');
const { build } = require('./utils');

class BenchmarkRunner extends Runner {
compiler() {
const config = merge(
defaultWebpackConfig(this.dir, this.env, this.options),
{
entry: [
require.resolve('./setup-bench.js'),
...this.tests
],
module: { noParse: /src\/benchmark.js/ },
resolve: { alias: { benchmark: path.resolve(__dirname, 'setup-bench.js') } }
const plugin = {
name: 'swap benchmark',
setup(build) {
build.onResolve({ filter: /^benchmark$/ }, () => {
return { path: path.join(__dirname, 'setup-bench.js') };
});
}
);
};

return webpack(config);
return build(this, { plugins: [plugin] });
}
}

Expand Down
Loading