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

Wrap @web/test-runner binary #65

Merged
merged 30 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
030f8a3
Add d2l-test binary
bearfriend Jul 10, 2023
fde5e92
Map browser names in getBrowsers
bearfriend Jul 11, 2023
0b8bb58
Cleanup
bearfriend Jul 11, 2023
ba6172a
Fix option handling
bearfriend Jul 11, 2023
50274ed
Move WTRConfig class back out of test binary
bearfriend Jul 11, 2023
f9a1ab0
Add option aliases
bearfriend Jul 11, 2023
639cd8a
Fix imports
bearfriend Jul 11, 2023
f69e831
Delete server/index.js
bearfriend Jul 11, 2023
754e0fc
Remove HEY!
bearfriend Jul 11, 2023
f098c03
Install config-loader
bearfriend Jul 12, 2023
31fe6f8
Remove options that wtr shouldn't use
bearfriend Jul 12, 2023
719c7b5
Add --help
bearfriend Jul 12, 2023
4e18fb1
Add unit group when used
bearfriend Jul 12, 2023
71332f5
Update filter comment
bearfriend Jul 12, 2023
65a67c7
Add --help details
bearfriend Jul 12, 2023
b4ff126
Use proper node imports
bearfriend Jul 12, 2023
e4719e9
Add support for filtering custom group files
bearfriend Jul 12, 2023
14d85d2
unit -> test
bearfriend Jul 13, 2023
1858d00
Check for unknown group
bearfriend Jul 13, 2023
0236ee4
Reorganize and fix/add tests
bearfriend Jul 19, 2023
92609c2
Clarify --golden description
bearfriend Jul 19, 2023
b2d4060
Simplify pattern
bearfriend Jul 19, 2023
904434c
Fix lint
bearfriend Jul 19, 2023
0a68bd0
Fix test
bearfriend Jul 19, 2023
7a87801
Fix option descriptions
bearfriend Jul 20, 2023
a131243
Rename things
bearfriend Jul 20, 2023
b90739b
Fix test:vdiff script
bearfriend Jul 20, 2023
674aab2
Accept all browser names
bearfriend Jul 20, 2023
b972f3d
Fix browser tests
bearfriend Jul 20, 2023
c2784fb
Dedupe browsers
bearfriend Jul 20, 2023
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
7 changes: 7 additions & 0 deletions bin/d2l-test-runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env node
import { argv } from 'node:process';
import { runner } from '../src/server/cli/test-runner.js';

const options = await runner.getOptions(argv);

await runner.start(options);
5 changes: 5 additions & 0 deletions package-lock.json

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

17 changes: 11 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
"scripts": {
"lint": "eslint . --ext .js",
"start": "web-dev-server --root-dir ./.vdiff --open ./.report/",
"test": "npm run lint && npm run test:server && npm run test:browser",
"test:browser": "web-test-runner --files \"./test/browser/**/*.test.js\" --node-resolve --playwright",
"test:server": "mocha ./test/server/**/*.test.js",
"test:vdiff": "web-test-runner --config ./test/browser/wtr-vdiff.config.js --group vdiff",
"test": "npm run lint && npm run test:bin && npm run test:server && npm run test:browser",
"test:bin": "mocha './test/bin/**/*.test.js'",
"test:browser": "web-test-runner --files './test/browser/**/*.test.js' --node-resolve --playwright",
"test:server": "mocha './test/server/**/*.test.js'",
"test:vdiff": "npx d2l-test-runner --config ./test/browser/vdiff.config.js --group vdiff",
"test:vdiff:golden": "npm run test:vdiff -- --golden"
},
"bin": {
"d2l-test-runner": "./bin/d2l-test-runner.js"
},
"author": "D2L Corporation",
"license": "Apache-2.0",
"devDependencies": {
Expand All @@ -24,8 +28,7 @@
"sinon": "^15"
},
"exports": {
".": "./src/browser/index.js",
"./wtr-config.js": "./src/server/index.js"
".": "./src/browser/index.js"
},
"files": [
"/src"
Expand All @@ -36,11 +39,13 @@
"dependencies": {
"@rollup/plugin-node-resolve": "^15",
"@open-wc/testing": "^3",
"@web/config-loader": "^0.2",
"@web/rollup-plugin-html": "^2",
"@web/test-runner": "^0.16",
"@web/test-runner-commands": "^0.7",
"@web/test-runner-playwright": "^0.10",
"command-line-args": "^5",
"command-line-usage": "^7",
"glob": "^10",
"lit": "^2",
"page": "^1",
Expand Down
159 changes: 159 additions & 0 deletions src/server/cli/test-runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import { ConfigLoaderError, readConfig } from '@web/config-loader';
import commandLineArgs from 'command-line-args';
import commandLineUsage from 'command-line-usage';
import process from 'node:process';
import { startTestRunner } from '@web/test-runner';
import { WTRConfig } from '../wtr-config.js';

async function getTestRunnerOptions(argv = []) {

const DISALLOWED_OPTIONS = ['--browsers', '--playwright', '--puppeteer', '--groups'];

const optionDefinitions = [
// web-test-runner options
{
name: 'files',
type: String,
multiple: true,
description: 'Test files to run. Path or glob.\n[Default: ./test/**/*.<group>.js]',
order: 8
},
{
name: 'group',
type: String,
required: true,
defaultOption: true,
description: 'Name of the group to run tests for\n[Default: test]',
order: 1
},
{
name: 'manual',
type: Boolean,
description: 'Starts test runner in manual testing mode. Ignores browser options and prints manual testing URL.\n{underline Not compatible with automated browser interactions}\nConsider using --watch to debug in the browser instead.',
order: 11
},
{
name: 'watch',
type: Boolean,
description: 'Reload tests on file changes. Allows debugging in all browsers.',
order: 9
},

// d2l-test-runner options
{
name: 'chrome',
type: Boolean,
description: 'Run tests in Chromium',
order: 2
},
{
name: 'config',
alias: 'c',
type: String,
description: 'Location to read config file from\n[Default: ./d2l-test-runner.config.js]',
order: 9
},
{
name: 'filter',
alias: 'f',
type: String,
multiple: true,
description: 'Filter test files by replacing wildcards with this glob',
order: 6
},
{
name: 'firefox',
type: Boolean,
description: 'Run tests in Firefox',
order: 3
},
{
name: 'golden',
type: Boolean,
description: 'Generate new golden screenshots. Ignored unless group is "vdiff".',
order: 10
},
{
name: 'grep',
alias: 'g',
type: String,
description: 'Only run tests matching this string or regexp',
order: 7
},
{
name: 'help',
type: Boolean,
description: 'Print usage information and exit',
order: 12
},
{
name: 'safari',
type: Boolean,
description: 'Run tests in Webkit',
order: 4
},
{
name: 'timeout',
alias: 't',
type: Number,
description: 'Test timeout threshold in ms\n[Default: 2000]',
order: 5
},
];

const cliArgs = commandLineArgs(optionDefinitions, { partial: true, argv });

if (cliArgs.help) {
const help = commandLineUsage([
{
header: 'D2L Test',
content: 'Test runner for D2L components and applications'
},
{
header: 'Usage',
content: 'd2l-test-runner [options]',
},
{
header: 'Options',
optionList: optionDefinitions
.map(o => (o.description += '\n') && o)
.filter(o => 'order' in o)
.sort((a, b) => (a.order > b.order ? 1 : -1))
}
]);
process.stdout.write(help);
process.exit();
}

cliArgs._unknown = cliArgs._unknown?.filter(o => !DISALLOWED_OPTIONS.includes(o));

const testConfig = await readConfig('d2l-test-runner.config', cliArgs.config).catch(err => {
if (err instanceof ConfigLoaderError) {
throw new Error(err.message);
} else {
throw err;
}
}) || {};

const wtrConfig = new WTRConfig(cliArgs);
const config = wtrConfig.create(testConfig);

argv = [
'--group', cliArgs.group,
...(cliArgs._unknown || [])
];
// copy cli-only wtr options back to argv to be processed
cliArgs.watch && argv.push('--watch');
cliArgs.manual && argv.push('--manual');

return {
argv,
config,
readFileConfig: false
};
}

export const runner = {
getOptions: getTestRunnerOptions,
start: startTestRunner
};
1 change: 1 addition & 0 deletions src/server/headed-mode-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export function headedMode({ manual, watch, pattern }) {
name: 'brightspace-headed-mode',
async transform(context) {
if ((watch || manual) && files.includes(context.path.slice(1))) {
// allow time to open devtools in firefox and webkit
watch && await new Promise(r => setTimeout(r, 2000));
return `debugger;\n${context.body}`;
}
Expand Down
1 change: 0 additions & 1 deletion src/server/index.js
bearfriend marked this conversation as resolved.
Outdated
Show resolved Hide resolved

This file was deleted.

10 changes: 5 additions & 5 deletions src/server/visual-diff-reporter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { cpSync, mkdirSync, rmSync, writeFileSync } from 'fs';
import { dirname, join } from 'path';
import { cpSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
dlockhart marked this conversation as resolved.
Show resolved Hide resolved
import { getTestInfo, PATHS } from './visual-diff-plugin.js';
import { execSync } from 'child_process';
import { fileURLToPath } from 'url';
import { execSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';

const __dirname = dirname(fileURLToPath(import.meta.url));

Expand Down Expand Up @@ -112,7 +112,7 @@ export function visualDiffReporter({ reportResults = true } = {}) {
cpSync(inputDir, tempDir, { force: true, recursive: true });
writeFileSync(join(tempDir, 'data.js'), `export default ${json};`);

execSync(`rollup -c ${join(__dirname, './rollup.config.js')}`);
execSync(`npx rollup -c ${join(__dirname, './rollup.config.js')}`, { stdio: 'pipe' });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npx fixes command not found error, which I believe is necessary now the way this runs.

stdio fixes the double output, though I'm not sure why, since it's supposed to be the default. May need to make this ignore if it spits out other bad things.


rmSync(tempDir, { recursive: true });

Expand Down
Loading