Skip to content

Commit 6ec7691

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

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

lib/github/tree.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ 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+
// Sometimes this function is in a spinner, and we need to print the error
42+
// after a new line.
43+
console.log();
44+
throw new Error(`Cannot find WPT for "${path}". Please check the WPT name.`);
45+
}
46+
return targetHistoryNodes[0].oid;
3947
}
4048

4149
/**

test/unit/wpt_updater.test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 = cli = new TestCLI();
24+
request = {
25+
gql: sinon.stub()
26+
};
27+
nodedir = '.';
28+
request.gql.withArgs(
29+
'LastCommit',
30+
{ path: UNKNOWN_PATH }
31+
).returns(Promise.resolve(emptyData));
32+
});
33+
34+
after(() => {
35+
cli.clearCalls();
36+
});
37+
38+
it('throws meaningful error when WPT name not found', async() => {
39+
path = UNKNOWN_PATH;
40+
wptUpdater = new WPTUpdater(path, cli, request, nodedir);
41+
let thrown = null;
42+
try {
43+
await wptUpdater.update();
44+
} catch (err) {
45+
thrown = err;
46+
}
47+
48+
assert(thrown instanceof Error);
49+
assert(thrown.message, `Cannot find WPT for "${path}". Please check the WPT name.`);
50+
});
51+
});

0 commit comments

Comments
 (0)