Skip to content

Commit

Permalink
fix(require-hook): False positive when using new options argument
Browse files Browse the repository at this point in the history
  • Loading branch information
mskelton committed Feb 28, 2024
1 parent c25d200 commit 8a06748
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/rules/require-hook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ runRuleTester('require-hook', rule, {
`,
errors: [{ column: 3, line: 2, messageId }],
},
{
code: dedent`
test.describe('some tests', { tag: '@slow' }, () => {
setup();
});
`,
errors: [{ column: 3, line: 2, messageId }],
},
{
code: dedent`
let { setup } = require('./test-utils');
Expand Down Expand Up @@ -135,11 +143,13 @@ runRuleTester('require-hook', rule, {
valid: [
'test.use({ locale: "en-US" })',
'test("some test", async ({ page }) => { })',
'test("some test", { tag: "@slow" }, async ({ page }) => { })',
'test.only("some test", async ({ page }) => { })',
'test.skip("some test", async ({ page }) => { })',
'test.fixme("some test", async ({ page }) => { })',
{ code: 'test.describe()' },
{ code: 'test.describe("just a title")' },
{ code: 'test.describe("just a title", { tag: "@slow" })' },
{ code: 'test.describe.configure({ mode: "parallel" })' },
{
code: dedent`
Expand All @@ -152,6 +162,17 @@ runRuleTester('require-hook', rule, {
});
`,
},
{
code: dedent`
test.describe.configure({ mode: 'parallel' });
test.describe('A, runs in parallel with B', { tag: "@slow" }, () => {
test.describe.configure({ mode: 'default' });
test('in order A1', async ({ page }) => {});
test('in order A2', { tag: "@slow" }, async ({ page }) => {});
});
`,
},
dedent`
test.describe('a test', () =>
test('something', () => {
Expand Down
3 changes: 1 addition & 2 deletions src/rules/require-hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ export default {
return;
}

const [, testFn] = node.arguments;

const testFn = node.arguments.at(-1);
if (!isFunction(testFn) || testFn.body.type !== 'BlockStatement') {
return;
}
Expand Down

0 comments on commit 8a06748

Please sign in to comment.