Skip to content

Commit 9224469

Browse files
jazellyjoyeecheung
authored andcommitted
chore(wpt): warn for non-existent wpt path
1 parent aa25318 commit 9224469

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

lib/github/tree.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,16 @@ export default class GitHubTree {
3535
branch,
3636
path
3737
});
38-
return data.repository.ref.target.history.nodes[0].oid;
38+
39+
const targetHistoryNodes = data.repository.ref.target.history.nodes;
40+
if (!targetHistoryNodes.length) {
41+
this.cli.stopSpinner(
42+
`Cannot find commit for "${path}". Please check the path name.`,
43+
this.cli.SPINNER_STATUS.FAILED
44+
);
45+
throw new Error(`Cannot find commit for "${path}"`);
46+
}
47+
return targetHistoryNodes[0].oid;
3948
}
4049

4150
/**

test/unit/wpt_updater.test.js

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

0 commit comments

Comments
 (0)