Skip to content

Commit 2cf9bc7

Browse files
committed
chore(wpt): throw better error when wpt path does not exist
1 parent aa25318 commit 2cf9bc7

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

lib/github/tree.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,29 @@ export default class GitHubTree {
2929

3030
async _getLastCommit() {
3131
const { request, owner, repo, branch, path } = this;
32+
console.log('asdasd', COMMIT_QUERY, {
33+
owner,
34+
repo,
35+
branch,
36+
path
37+
});
3238
const data = await request.gql(COMMIT_QUERY, {
3339
owner,
3440
repo,
3541
branch,
3642
path
3743
});
38-
return data.repository.ref.target.history.nodes[0].oid;
44+
45+
console.log('data', data);
46+
const targetHistoryNodes = data.repository.ref.target.history.nodes;
47+
if (!targetHistoryNodes.length) {
48+
this.cli.stopSpinner(
49+
`Cannot find WPT for "${path}". Please check the WPT name.`,
50+
this.cli.SPINNER_STATUS.FAILED
51+
);
52+
process.exit();
53+
}
54+
return targetHistoryNodes[0].oid;
3955
}
4056

4157
/**

test/unit/wpt_updater.test.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { describe, it, before, after } from 'node:test';
2+
import TestCLI from '../fixtures/test_cli.js';
3+
import sinon from 'sinon';
4+
5+
import { WPTUpdater } from '../../lib/wpt/index.js';
6+
7+
describe('WPTUpdater', function() {
8+
const UNKNOWN_PATH = 'unknown path';
9+
let request;
10+
let wptUpdater;
11+
let nodedir;
12+
let cli;
13+
let path;
14+
const emptyData = {
15+
repository:
16+
{
17+
ref: { target: { history: { nodes: [] } } }
18+
}
19+
};
20+
21+
before(() => {
22+
cli = new TestCLI();
23+
request = {
24+
gql: sinon.stub()
25+
};
26+
nodedir = '.';
27+
request.gql.withArgs(
28+
'LastCommit',
29+
{
30+
owner: 'web-platform-tests',
31+
repo: 'wpt',
32+
branch: 'master',
33+
path: UNKNOWN_PATH
34+
}
35+
).returns(Promise.resolve(emptyData));
36+
});
37+
38+
after(() => {
39+
cli.clearCalls();
40+
});
41+
42+
it('exits with meaningful error when WPT name not found', async() => {
43+
path = UNKNOWN_PATH;
44+
wptUpdater = new WPTUpdater(path, cli, request, nodedir);
45+
await wptUpdater.update();
46+
cli.assertCalledWith(
47+
{
48+
warn: [[
49+
`Cannot find WPT for "${path}". Please check the WPT name.`,
50+
{ newline: true }
51+
]]
52+
}, { ignore: ['startSpinner', 'updateSpinner'] });
53+
});
54+
});

0 commit comments

Comments
 (0)