Skip to content

Commit

Permalink
make .record() take a TestSpecID
Browse files Browse the repository at this point in the history
  • Loading branch information
kainino0x committed Jul 8, 2019
1 parent c66c7d1 commit 3861f01
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
8 changes: 5 additions & 3 deletions src/framework/logger.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { ParamsSpec } from './params/index.js';
import { getStackTrace, now } from './util.js';
import { version } from './version.js';
import { TestSpecID } from './id.js';
import { makeQueryString } from './url_query.js';

type Status = 'running' | 'pass' | 'warn' | 'fail';
interface TestLiveResult {
path: string;
spec: string;
cases: TestCaseLiveResult[];
}

Expand All @@ -21,9 +23,9 @@ export class Logger {

constructor() {}

record(path: string): [GroupRecorder, TestLiveResult] {
record(spec: TestSpecID): [GroupRecorder, TestLiveResult] {
const cases: TestCaseLiveResult[] = [];
const result: TestLiveResult = { path, cases };
const result: TestLiveResult = { spec: makeQueryString(spec), cases };
this.results.push(result);
return [new GroupRecorder(result), result];
}
Expand Down
4 changes: 1 addition & 3 deletions src/runtime/cmdline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ for (const a of process.argv.slice(2)) {
continue;
}

const [rec] = log.record(qr.id.path);
const [rec] = log.record(qr.id);
for (const t of qr.spec.g.iterate(rec)) {
running.push(
(async () => {
Expand Down Expand Up @@ -89,15 +89,13 @@ for (const a of process.argv.slice(2)) {
console.log('');
console.log('** Warnings **');
for (const [id, r] of warned) {
// TODO: actually print query here
console.log(makeQueryString(id), r);
}
}
if (failed.length) {
console.log('');
console.log('** Failures **');
for (const [id, r] of failed) {
// TODO: actually print query here
console.log(makeQueryString(id), r);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/standalone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function mkCase(testcasesVis: HTMLElement, query: string, t: RunCase) {
continue;
}

const [tRec] = log.record(qr.id.path);
const [tRec] = log.record(qr.id);
for (const t of qr.spec.g.iterate(tRec)) {
const query = makeQueryString(qr.id, t.id);
const runCase = mkCase(testcasesVis, query, t);
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/wpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ declare function async_test(f: (this: WptTestObject) => Promise<void>, name: str
continue;
}

const [rec] = log.record(qr.id.path);
const [rec] = log.record(qr.id);
// TODO: don't run all tests all at once
for (const t of qr.spec.g.iterate(rec)) {
const run = t.run();
Expand Down
8 changes: 4 additions & 4 deletions src/suites/unittests/loading.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class LoadingTest extends DefaultFixture {
}

async singleGroup(query: string): Promise<RunCase[]> {
const [rec] = new Logger().record('');
const [rec] = new Logger().record({ suite: '', path: '' });
const a = await this.load([query]);
if (a.length !== 1) {
throw new Error('more than one group');
Expand Down Expand Up @@ -142,7 +142,7 @@ g.test('whole group', async t => {
if (foo.spec.g === undefined) {
throw new Error('foo group');
}
const [rec] = new Logger().record('');
const [rec] = new Logger().record({ suite: '', path: '' });
t.expect(Array.from(foo.spec.g.iterate(rec)).length === 3);
}
});
Expand Down Expand Up @@ -188,7 +188,7 @@ g.test('end2end', async t => {
t.expect(l[0].spec.g.iterate instanceof Function);

const log = new Logger();
const [rec, res] = log.record(l[0].id.path);
const [rec, res] = log.record(l[0].id);
const rcs = Array.from(l[0].spec.g.iterate(rec));
if (rcs.length !== 2) {
throw new Error('iterate length');
Expand All @@ -201,7 +201,7 @@ g.test('end2end', async t => {
t.expect(paramsEquals(rcs[1].id.params, {}));

t.expect(log.results[0] === res);
t.expect(res.path === 'foof');
t.expect(res.spec === 'suite2:foof:');
t.expect(res.cases.length === 0);

{
Expand Down
12 changes: 6 additions & 6 deletions src/suites/unittests/logger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export const g = new TestGroup(DefaultFixture);

g.test('construct', t => {
const mylog = new Logger();
const [testrec, testres] = mylog.record('foo/bar');
const [testrec, testres] = mylog.record({ suite: 'a', path: 'foo/bar' });
const [, res1] = testrec.record('baz', null);
const params2 = {};
const [, res2] = testrec.record('qux', params2);

t.expect(testres.path === 'foo/bar');
t.expect(testres.spec === 'a:foo/bar:');
t.expect(testres.cases.length === 2);
t.expect(testres.cases[0] === res1);
t.expect(testres.cases[1] === res2);
Expand All @@ -35,7 +35,7 @@ g.test('construct', t => {

g.test('empty', t => {
const mylog = new Logger();
const [testrec] = mylog.record('');
const [testrec] = mylog.record({ suite: '', path: '' });
const [rec, res] = testrec.record('baz', null);

rec.start();
Expand All @@ -47,7 +47,7 @@ g.test('empty', t => {

g.test('pass', t => {
const mylog = new Logger();
const [testrec] = mylog.record('');
const [testrec] = mylog.record({ suite: '', path: '' });
const [rec, res] = testrec.record('baz', null);

rec.start();
Expand All @@ -60,7 +60,7 @@ g.test('pass', t => {

g.test('warn', t => {
const mylog = new Logger();
const [testrec] = mylog.record('');
const [testrec] = mylog.record({ suite: '', path: '' });
const [rec, res] = testrec.record('baz', null);

rec.start();
Expand All @@ -73,7 +73,7 @@ g.test('warn', t => {

g.test('fail', t => {
const mylog = new Logger();
const [testrec] = mylog.record('');
const [testrec] = mylog.record({ suite: '', path: '' });
const [rec, res] = testrec.record('baz', null);

rec.start();
Expand Down
4 changes: 2 additions & 2 deletions src/suites/unittests/test_group_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { TestCaseID } from '../../framework/id.js';

export class TestGroupTest extends DefaultFixture {
async run<F extends Fixture>(g: TestGroup<F>): Promise<void> {
const [rec] = new Logger().record('');
const [rec] = new Logger().record({ suite: '', path: '' });
await Promise.all(Array.from(g.iterate(rec)).map(test => test.run()));
}

enumerate<F extends Fixture>(g: TestGroup<F>): TestCaseID[] {
const cases = [];
const [rec] = new Logger().record('');
const [rec] = new Logger().record({ suite: '', path: '' });
for (const test of g.iterate(rec)) {
cases.push(test.id);
}
Expand Down

0 comments on commit 3861f01

Please sign in to comment.