-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: standardize testkit package with lint, config, plugins (#2601)
- Loading branch information
1 parent
ddd22e0
commit 798497f
Showing
27 changed files
with
251 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const defaultPlugins = ["prettier"]; | ||
const defaultExtends = ["eslint:recommended", "plugin:prettier/recommended"]; | ||
const defaultRules = { | ||
"prettier/prettier": "error" | ||
}; | ||
|
||
const commonJsPlugins = defaultPlugins; | ||
const commonJsExtends = defaultExtends; | ||
const commonJsRules = { | ||
...defaultRules, | ||
"no-unused-vars": ["error", { argsIgnorePattern: "^_" }] | ||
}; | ||
|
||
const commonTsPlugins = [...defaultPlugins, "@typescript-eslint"]; | ||
const commonTsExtends = [...defaultExtends, "plugin:@typescript-eslint/recommended"]; | ||
const commonTsRules = { | ||
...defaultRules, | ||
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }], | ||
"@typescript-eslint/no-explicit-any": "warn" | ||
}; | ||
|
||
module.exports = { | ||
ignorePatterns: ["node_modules", "dist"], | ||
parserOptions: { | ||
sourceType: "module" | ||
}, | ||
env: { | ||
es2021: true, | ||
node: true | ||
}, | ||
overrides: [ | ||
{ | ||
files: ["**/*.js"], | ||
extends: commonJsExtends, | ||
plugins: commonJsPlugins, | ||
rules: commonJsRules | ||
}, | ||
{ | ||
files: ["**/*.ts"], | ||
parser: "@typescript-eslint/parser", | ||
plugins: commonTsPlugins, | ||
extends: commonTsExtends, | ||
rules: commonTsRules | ||
}, | ||
{ | ||
files: ["./__tests__/*.test.js"], | ||
plugins: [...commonJsPlugins, "playwright"], | ||
extends: [...commonJsExtends, "plugin:playwright/recommended"], | ||
rules: commonJsRules | ||
}, | ||
{ | ||
files: ["./__tests__/*.test.ts"], | ||
parser: "@typescript-eslint/parser", | ||
plugins: [...commonTsPlugins, "playwright"], | ||
extends: [...commonTsExtends, "plugin:playwright/recommended"], | ||
rules: commonTsRules | ||
} | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { test, expect } from "@playwright/test"; | ||
import { Button } from "../buttons/Button"; | ||
import { buttonStory } from "./utils/url-helper"; | ||
|
||
test("should fire a click event and log to console", async ({ page }) => { | ||
// Navigate to the Storybook page with the component | ||
await page.goto(buttonStory, { timeout: 100000 }); | ||
// Locate the iframe where the button is rendered | ||
const frame = page.frameLocator("[id='storybook-preview-iframe']"); | ||
const button = new Button(page, frame.locator('button[data-testid="button"]'), "Button"); | ||
|
||
//TODO - find a better way to wait for the storybook to load | ||
while ((await button.locator.isVisible()) === false) { | ||
// eslint-disable-next-line playwright/no-wait-for-timeout | ||
await page.waitForTimeout(30000); | ||
await page.reload(); | ||
// eslint-disable-next-line playwright/no-conditional-in-test | ||
if ((await button.locator.isVisible()) === true) { | ||
break; | ||
} | ||
} | ||
// Add a listener to capture console logs | ||
let consoleMessage = ""; | ||
page.on("console", async msg => { | ||
const values = await Promise.all(msg.args().map(arg => arg.jsonValue())); | ||
consoleMessage = values.join(" "); | ||
}); | ||
|
||
// Attach a click event listener that logs a message to the console | ||
await button.locator.evaluate(buttonElement => { | ||
buttonElement.addEventListener("click", () => { | ||
console.log("Button clicked"); // Log to console when clicked | ||
}); | ||
}); | ||
// Click the button | ||
await button.click(); | ||
|
||
// eslint-disable-next-line playwright/no-wait-for-timeout -- Wait a bit to ensure the console log is captured | ||
await page.waitForTimeout(500); | ||
|
||
// Verify the console log contains the expected message | ||
expect(consoleMessage).toContain("Button clicked"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { test, expect } from "@playwright/test"; | ||
import { Checkbox } from "../inputs/Checkbox"; | ||
import { checkboxStory } from "./utils/url-helper"; | ||
|
||
test.describe("menuButton Class with Storybook", () => { | ||
let checkbox; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto(checkboxStory); | ||
const frame = page.frameLocator("[id='storybook-preview-iframe']"); | ||
const checkboxLocator = frame.locator('[data-testid="checkbox-checkbox"]'); | ||
checkbox = new Checkbox(page, checkboxLocator, "Test checkbox button"); | ||
}); | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
test("set checkbox", async ({ page }) => { | ||
// eslint-disable-next-line playwright/no-conditional-in-test | ||
if (await checkbox.isChecked()) { | ||
await checkbox.setChecked(false); | ||
// eslint-disable-next-line playwright/prefer-web-first-assertions, playwright/no-conditional-expect | ||
expect(await checkbox.isChecked()).toBe(false); | ||
} else { | ||
await checkbox.setChecked(true); | ||
// eslint-disable-next-line playwright/prefer-web-first-assertions, playwright/no-conditional-expect | ||
expect(await checkbox.isChecked()).toBe(true); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.