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

expose "slow" CLI parameter and pass-through to Mocha #101

Merged
merged 4 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
11 changes: 9 additions & 2 deletions src/server/cli/test-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async function getTestRunnerOptions(argv = []) {
name: 'golden',
type: Boolean,
description: 'Generate new golden screenshots. Ignored unless group is "vdiff".',
order: 13
order: 14
},
{
name: 'grep',
Expand All @@ -83,7 +83,7 @@ async function getTestRunnerOptions(argv = []) {
name: 'help',
type: Boolean,
description: 'Print usage information and exit',
order: 14
order: 15
},
{
name: 'open',
Expand All @@ -96,6 +96,13 @@ async function getTestRunnerOptions(argv = []) {
longAlias: 'webkit',
type: Boolean
},
{
name: 'slow',
alias: 's',
type: Number,
description: 'Tests whose duration in milliseconds are at most half of this threshold are "fast" and tests which exceed it are "slow"\n[Default: 75]',
dlockhart marked this conversation as resolved.
Show resolved Hide resolved
order: 13
},
{
name: 'slowmo',
type: Number,
Expand Down
13 changes: 11 additions & 2 deletions src/server/wtr-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const BROWSER_MAP = {
safari: 'webkit',
webkit: 'webkit'
};
const DEFAULT_VDIFF_SLOW = 500;
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm guessing we'll want to tweak this later once we have vdiff running in core and have a better idea of what "slow" means for visual-diff. We may also want different values locally compared to CI.


export class WTRConfig {

Expand Down Expand Up @@ -119,27 +120,35 @@ export class WTRConfig {
}).flat();
}

#getMochaConfig(timeoutConfig) {
#getMochaConfig(group, slowConfig, timeoutConfig) {
const {
timeout = timeoutConfig,
grep,
open,
slow = slowConfig,
watch
} = this.#cliArgs;

if (typeof timeout !== 'undefined' && typeof timeout !== 'number') throw new TypeError('timeout must be a number');
if (typeof slow !== 'undefined' && typeof slow !== 'number') throw new TypeError('slow must be a number');

const config = {};

if (timeout) config.timeout = String(timeout);
if (open || watch) config.timeout = '0';
if (grep) config.grep = grep;
if (slow) {
config.slow = String(slow);
} else if (group === 'vdiff') {
config.slow = String(DEFAULT_VDIFF_SLOW);
}

return Object.keys(config).length && { testFramework: { config } };
}

create({
pattern = DEFAULT_PATTERN,
slow,
timeout,
...passthroughConfig
} = {}) {
Expand All @@ -158,7 +167,7 @@ export class WTRConfig {

const config = {
...this.#defaultConfig,
...this.#getMochaConfig(timeout),
...this.#getMochaConfig(group, slow, timeout),
...passthroughConfig
};

Expand Down
5 changes: 3 additions & 2 deletions test/server/cli/test-runner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@ describe('runner.getOptions()', () => {
'-c', './test/browser/vdiff.config.js',
'-f', 'abc',
'-g', 'ghi',
'-t', 123]
'-t', 123,
'-s', 456]
);
expect(opts.argv).to.deep.equal(['--group', 'test']);
expect(opts.config.groups[0]).to.deep.include({
name: 'test',
files: [ 'test/browser/**/+(abc.vdiff.js)' ]
});
expect(opts.config.testFramework).to.deep.include({
config: { timeout: '123', grep: 'ghi' }
config: { timeout: '123', grep: 'ghi', slow: '456' }
});
});

Expand Down
41 changes: 41 additions & 0 deletions test/server/wtr-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,47 @@ describe('WTRConfig', () => {
});
});

it('should throw for invalid timeout value', () => {
expect(() => wtrConfig.create({ timeout: 'never' }))
.to.throw(TypeError, 'timeout must be a number');
});

it('should configure testFramework when provided with a slow value', () => {
const config = wtrConfig.create({ slow: 1234 });
expect(config.testFramework).to.not.be.undefined;
expect(config.testFramework.config).to.not.be.undefined;
expect(config.testFramework.config.slow).to.equal('1234');
});

it('should set slow from CLI when provided', () => {
const wtrConfig = new WTRConfig({ slow: 1234 });
const config = wtrConfig.create({ slow: 5678 });
expect(config.testFramework.config.slow).to.equal('1234');
});

it('should default slow to a higher value for vdiff group', () => {
const wtrConfig = new WTRConfig({ group: 'vdiff' });
const config = wtrConfig.create();
expect(config.testFramework.config.slow).to.equal('500');
});

it('should set slow from CLI even for vdiff group', () => {
const wtrConfig = new WTRConfig({ group: 'vdiff', slow: 1234 });
const config = wtrConfig.create();
expect(config.testFramework.config.slow).to.equal('1234');
});

it('should set slow from config even for vdiff group', () => {
const wtrConfig = new WTRConfig({ group: 'vdiff' });
const config = wtrConfig.create({ slow: 5678 });
expect(config.testFramework.config.slow).to.equal('5678');
});

it('should throw for invalid slow value', () => {
expect(() => wtrConfig.create({ slow: 'fast' }))
.to.throw(TypeError, 'slow must be a number');
});

it('should set a common default files pattern', () => {
expect(config.groups[0].files).to.deep.equal(['./test/**/*.test.js']);
});
Expand Down