Skip to content

Commit

Permalink
Merge pull request #265 from playwright-community/new-test-syntax-tags
Browse files Browse the repository at this point in the history
feat: Add support for new test option syntax
  • Loading branch information
mskelton authored Feb 28, 2024
2 parents d51f043 + e7155b6 commit 99f11c7
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/rules/no-skipped-test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ runRuleTester('no-skipped-test', rule, {
},
],
},
{
code: 'test.skip("a test", { tag: ["@fast", "@login"] }, () => {})',
errors: [
{
column: 6,
endColumn: 10,
line: 1,
messageId: 'noSkippedTest',
suggestions: [
{
messageId,
output: 'test("a test", { tag: ["@fast", "@login"] }, () => {})',
},
],
},
],
},
{
code: 'test.describe.skip("skip this describe", () => {});',
errors: [
Expand Down Expand Up @@ -233,6 +250,8 @@ runRuleTester('no-skipped-test', rule, {
],
valid: [
'test("a test", () => {});',
'test("a test", { tag: "@fast" }, () => {});',
'test("a test", { tag: ["@fast", "@report"] }, () => {});',
'test.describe("describe tests", () => {});',
'test.describe.only("describe focus tests", () => {});',
'test.describ["only"]("describe focus tests", () => {});',
Expand Down
13 changes: 13 additions & 0 deletions src/rules/require-top-level-describe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ runRuleTester('require-top-level-describe', rule, {
{ column: 1, endColumn: 13, line: 1, messageId: 'unexpectedTest' },
],
},
{
code: 'test("foo", { tag: ["@fast"] }, () => {})',
errors: [
{ column: 1, endColumn: 5, line: 1, messageId: 'unexpectedTest' },
],
},
{
code: dedent`
test("foo", () => {})
Expand Down Expand Up @@ -210,6 +216,13 @@ runRuleTester('require-top-level-describe', rule, {
test.describe('two', () => {});
test.describe('three', () => {});
`,
dedent`
test.describe("suite", () => {
test("foo", { tag: ["@slow"] }, () => {})
test.describe("another suite", { tag: ["@slow"] }, () => {});
test("my other test", () => {})
});
`,
{
code: dedent`
test.describe('one', () => {
Expand Down
118 changes: 118 additions & 0 deletions src/utils/parseFnCall.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,57 @@ runRuleTester('test', rule, {
},
],
},
{
code: 'test("a test", { tag: ["@fast", "@login"] }, () => {});',
errors: [
{
column: 1,
data: expectedParsedFnCallResultData({
group: 'test',
head: {
local: 'test',
node: 'test',
original: null,
},
members: [],
name: 'test',
type: 'test',
}),
line: 1,
messageId: 'details',
},
],
},
{
code: dedent`
test('test full report', {
annotation: [
{ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/23180' },
{ type: 'docs', description: 'https://playwright.dev/docs/test-annotations#tag-tests' },
],
}, async ({ page }) => {
// ...
});
`,
errors: [
{
column: 1,
data: expectedParsedFnCallResultData({
group: 'test',
head: {
local: 'test',
node: 'test',
original: null,
},
members: [],
name: 'test',
type: 'test',
}),
line: 1,
messageId: 'details',
},
],
},
{
code: 'test.step("a step", () => {});',
errors: [
Expand Down Expand Up @@ -858,6 +909,73 @@ runRuleTester('describe', rule, {
},
],
},
{
code: dedent`
test.describe('group', {
tag: '@report',
}, () => {
test('test report header', async ({ page }) => {
// ...
});
test('test full report', {
tag: ['@slow', '@vrt'],
}, async ({ page }) => {
// ...
});
});
`,
errors: [
{
column: 1,
data: expectedParsedFnCallResultData({
group: 'describe',
head: {
local: 'test',
node: 'test',
original: null,
},
members: ['describe'],
name: 'describe',
type: 'describe',
}),
line: 1,
messageId: 'details',
},
{
column: 3,
data: expectedParsedFnCallResultData({
group: 'test',
head: {
local: 'test',
node: 'test',
original: null,
},
members: [],
name: 'test',
type: 'test',
}),
line: 4,
messageId: 'details',
},
{
column: 3,
data: expectedParsedFnCallResultData({
group: 'test',
head: {
local: 'test',
node: 'test',
original: null,
},
members: [],
name: 'test',
type: 'test',
}),
line: 8,
messageId: 'details',
},
],
},
{
code: 'context("when there is an error", () => {})',
errors: [
Expand Down
2 changes: 1 addition & 1 deletion src/utils/parseFnCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ function parse(
let type: FnType = group;
if (
(name === 'test' || name === 'describe') &&
(node.arguments.length !== 2 || !isFunction(node.arguments[1]))
(node.arguments.length < 2 || !isFunction(node.arguments.at(-1)))
) {
type = 'config';
}
Expand Down

0 comments on commit 99f11c7

Please sign in to comment.