Skip to content

Commit

Permalink
fix: correctly pass cli options to hermione "readTests" and "run"
Browse files Browse the repository at this point in the history
  • Loading branch information
DudaGod committed Jan 24, 2024
1 parent 0ac9684 commit f8f3018
Show file tree
Hide file tree
Showing 2 changed files with 176 additions and 28 deletions.
23 changes: 20 additions & 3 deletions lib/gui/tool-runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ import {ImagesInfoSaver} from '../../images-info-saver';
import {SqliteImageStore} from '../../image-store';

type ToolRunnerArgs = [paths: string[], hermione: Hermione & HtmlReporterApi, configs: GuiConfigs];
type ReplModeOption = {
enabled: boolean;
beforeTest: boolean;
onFail: boolean;
}

export type ToolRunnerTree = GuiReportBuilderResult & Pick<GuiCliOptions, 'autoRun'>;

Expand Down Expand Up @@ -128,8 +133,19 @@ export class ToolRunner {

async _readTests(): Promise<TestCollection> {
const {grep, set: sets, browser: browsers} = this._globalOpts;
const replMode = this._getReplModeOption();

return this._hermione.readTests(this._testFiles, {grep, sets, browsers});
return this._hermione.readTests(this._testFiles, {grep, sets, browsers, replMode});
}

_getReplModeOption(): ReplModeOption {
const {repl = false, replBeforeTest = false, replOnFail = false} = this._globalOpts;

return {
enabled: repl || replBeforeTest || replOnFail,
beforeTest: replBeforeTest,
onFail: replOnFail
};
}

protected _ensureReportBuilder(): GuiReportBuilder {
Expand Down Expand Up @@ -282,10 +298,11 @@ export class ToolRunner {
}

async run(tests: TestSpec[] = []): Promise<boolean> {
const {grep, set: sets, browser: browsers} = this._globalOpts;
const {grep, set: sets, browser: browsers, devtools = false} = this._globalOpts;
const replMode = this._getReplModeOption();

return createTestRunner(this._ensureTestCollection(), tests)
.run((collection) => this._hermione.run(collection, {grep, sets, browsers}));
.run((collection) => this._hermione.run(collection, {grep, sets, browsers, devtools, replMode}));
}

protected async _handleRunnableCollection(): Promise<void> {
Expand Down
181 changes: 156 additions & 25 deletions test/unit/lib/gui/tool-runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,28 +131,104 @@ describe('lib/gui/tool-runner/index', () => {
.then(() => assert.calledWith(reportBuilder.setApiValues, {foo: 'bar'}));
});

it('should pass paths to "readTests" method', () => {
const gui = initGuiReporter(hermione, {paths: ['foo', 'bar']});
describe('correctly pass options to "readTests" method', () => {
it('should pass "paths" option', () => {
const gui = initGuiReporter(hermione, {paths: ['foo', 'bar']});

return gui.initialize()
.then(() => assert.calledOnceWith(hermione.readTests, ['foo', 'bar']));
});
return gui.initialize()
.then(() => assert.calledOnceWith(hermione.readTests, ['foo', 'bar']));
});

it('should pass "grep", "sets" and "browsers" options to "readTests" method', () => {
const grep = 'foo';
const set = 'bar';
const browser = 'yabro';
it('should pass "grep", "sets" and "browsers" options', () => {
const grep = 'foo';
const set = 'bar';
const browser = 'yabro';

const gui = initGuiReporter(hermione, {
configs: {
program: {name: () => 'tool', grep, set, browser}
}
const gui = initGuiReporter(hermione, {
configs: {
program: {grep, set, browser}
}
});

return gui.initialize()
.then(() => {
assert.calledOnceWith(hermione.readTests, sinon.match.any, sinon.match({grep, sets: set, browsers: browser}));
});
});

return gui.initialize()
.then(() => {
assert.calledOnceWith(hermione.readTests, sinon.match.any, {grep, sets: set, browsers: browser});
describe('"replMode" option', () => {
it('should be disabled by default', async () => {
const gui = initGuiReporter(hermione, {
configs: {
program: {}
}
});

await gui.initialize();

assert.calledOnceWith(hermione.readTests, sinon.match.any, sinon.match({
replMode: {
enabled: false,
beforeTest: false,
onFail: false
}
}));
});

it('should be enabled when specify "repl" flag', async () => {
const gui = initGuiReporter(hermione, {
configs: {
program: {repl: true}
}
});

await gui.initialize();

assert.calledOnceWith(hermione.readTests, sinon.match.any, sinon.match({
replMode: {
enabled: true,
beforeTest: false,
onFail: false
}
}));
});

it('should be enabled when specify "beforeTest" flag', async () => {
const gui = initGuiReporter(hermione, {
configs: {
program: {replBeforeTest: true}
}
});

await gui.initialize();

assert.calledOnceWith(hermione.readTests, sinon.match.any, sinon.match({
replMode: {
enabled: true,
beforeTest: true,
onFail: false
}
}));
});

it('should be enabled when specify "onFail" flag', async () => {
const gui = initGuiReporter(hermione, {
configs: {
program: {replOnFail: true}
}
});

await gui.initialize();

assert.calledOnceWith(hermione.readTests, sinon.match.any, sinon.match({
replMode: {
enabled: true,
beforeTest: false,
onFail: true
}
}));
});
});
});

it('should not add disabled test to report', () => {
Expand Down Expand Up @@ -510,18 +586,73 @@ describe('lib/gui/tool-runner/index', () => {
hermione.readTests.resolves(collection);
});

it('should run hermione with passed opts', async () => {
const globalCliOpts = {grep: /some-grep/, set: 'some-set', browser: 'yabro'};
const configs = {...mkPluginConfig_(), ...mkToolCliOpts_(globalCliOpts)};
const gui = ToolGuiReporter.create([], hermione, configs);
describe('should run hermione with', () => {
const run_ = async (globalCliOpts = {}) => {
const configs = {...mkPluginConfig_(), ...mkToolCliOpts_(globalCliOpts)};
const gui = ToolGuiReporter.create([], hermione, configs);

await gui.initialize();
await gui.run();
await gui.initialize();
await gui.run();

const runHandler = runner.run.firstCall.args[0];
runHandler(collection);
const runHandler = runner.run.firstCall.args[0];
runHandler(collection);
};

it('passed opts', async () => {
await run_({grep: /some-grep/, set: 'some-set', browser: 'yabro', devtools: true});

assert.calledOnceWith(hermione.run, collection, sinon.match({grep: /some-grep/, sets: 'some-set', browsers: 'yabro', devtools: true}));
});

assert.calledOnceWith(hermione.run, collection, {grep: /some-grep/, sets: 'some-set', browsers: 'yabro'});
describe('"replMode" option', () => {
it('should be disabled by default', async () => {
await run_();

assert.calledOnceWith(hermione.run, collection, sinon.match({
replMode: {
enabled: false,
beforeTest: false,
onFail: false
}
}));
});

it('should be enabled when specify "repl" flag', async () => {
await run_({repl: true});

assert.calledOnceWith(hermione.run, collection, sinon.match({
replMode: {
enabled: true,
beforeTest: false,
onFail: false
}
}));
});

it('should be enabled when specify "beforeTest" flag', async () => {
await run_({replBeforeTest: true});

assert.calledOnceWith(hermione.run, collection, sinon.match({
replMode: {
enabled: true,
beforeTest: true,
onFail: false
}
}));
});

it('should be enabled when specify "onFail" flag', async () => {
await run_({replOnFail: true});

assert.calledOnceWith(hermione.run, collection, sinon.match({
replMode: {
enabled: true,
beforeTest: false,
onFail: true
}
}));
});
});
});
});

Expand Down

0 comments on commit f8f3018

Please sign in to comment.