Skip to content

Commit

Permalink
rewrite existing cypress tests to playwright (calcom#931)
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT authored Oct 13, 2021
1 parent 5c4f4bf commit dc4331e
Show file tree
Hide file tree
Showing 24 changed files with 346 additions and 689 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

5 changes: 3 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
},
"overrides": [
{
"files": ["cypress/**/*.js"],
"files": ["playwright/**/*.{js,jsx,tsx,ts}"],
"rules": {
"no-undef": "off"
"no-undef": "off",
"@typescript-eslint/no-non-null-assertion": "off"
}
}
],
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ jobs:
- run: yarn build
- run: yarn start &
- run: npx wait-port 3000 --timeout 10000
- run: yarn cypress run
- run: yarn playwright install-deps
- run: yarn test-playwright

Expand All @@ -69,6 +68,5 @@ jobs:
with:
name: videos
path: |
cypress/videos
cypress/screenshots
playwright/screenshots
playwright/videos
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# testing
/coverage
.nyc_output
cypress/videos
cypress/screenshots
playwright/videos
playwright/screenshots

Expand Down
13 changes: 13 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = function (api) {
api.cache(true);
const plugins = [];
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
console.log("------ 💯 Adding test coverage support 💯 ------");
plugins.push("istanbul");
}

return {
presets: ["next/babel"],
plugins,
};
};
5 changes: 0 additions & 5 deletions cypress/fixtures/example.json

This file was deleted.

62 changes: 0 additions & 62 deletions cypress/integration/booking-pages.spec.ts

This file was deleted.

24 changes: 0 additions & 24 deletions cypress/integration/cancel.spec.ts

This file was deleted.

66 changes: 0 additions & 66 deletions cypress/integration/event-types.spec.ts

This file was deleted.

6 changes: 0 additions & 6 deletions cypress/integration/smoke-test.spec.ts

This file was deleted.

23 changes: 0 additions & 23 deletions cypress/plugins/index.js

This file was deleted.

26 changes: 0 additions & 26 deletions cypress/support/commands.ts

This file was deleted.

2 changes: 0 additions & 2 deletions cypress/support/index.ts

This file was deleted.

10 changes: 0 additions & 10 deletions cypress/tsconfig.json

This file was deleted.

2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const config: Config.InitialOptions = {
verbose: true,
roots: ["<rootDir>"],
testMatch: ["**/tests/**/*.+(ts|tsx|js)", "**/?(*.)+(spec|test).+(ts|tsx|js)"],
testPathIgnorePatterns: ["<rootDir>/.next", "<rootDir>/playwright/", "<rootDir>/cypress/"],
testPathIgnorePatterns: ["<rootDir>/.next", "<rootDir>/playwright/"],
transform: {
"^.+\\.(js|jsx|ts|tsx)$": ["babel-jest", { presets: ["next/babel"] }],
},
Expand Down
18 changes: 13 additions & 5 deletions jest.playwright.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
const opts = {
// launch headless on CI, in browser locally
headless: !!process.env.CI || !!process.env.PLAYWRIGHT_HEADLESS,
executablePath: process.env.PLAYWRIGHT_CHROME_EXECUTABLE_PATH,
collectCoverage: !!process.env.PLAYWRIGHT_HEADLESS,
};

console.log("⚙️ Playwright options:", opts);

module.exports = {
verbose: true,
preset: "jest-playwright-preset",
Expand All @@ -10,16 +19,15 @@ module.exports = {
browsers: ["chromium" /*, 'firefox', 'webkit'*/],
exitOnPageError: false,
launchOptions: {
// launch headless on CI, in browser locally
headless: !!process.env.CI,
executablePath: process.env.PLAYWRIGHT_CHROME_EXECUTABLE_PATH,
headless: opts.headless,
executablePath: opts.executablePath,
},
contextOptions: {
recordVideo: {
dir: "playwright/videos/",
dir: "playwright/videos",
},
},
collectCoverage: true,
collectCoverage: opts.collectCoverage,
},
},
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"db-nuke": "docker-compose down --volumes --remove-orphans",
"dx": "cross-env BASE_URL=http://localhost:3000 JWT_SECRET=secret DATABASE_URL=postgresql://postgres:@localhost:5450/calendso run-s db-up db-migrate db-seed dev",
"test": "jest",
"test-playwright": "jest --maxWorkers=2 --config jest.playwright.config.js && nyc report --reporter=lcov",
"test-playwright": "jest --config jest.playwright.config.js",
"test-playwright-lcov": "cross-env PLAYWRIGHT_HEADLESS=1 PLAYWRIGHT_COVERAGE=1 yarn test-playwright && nyc report --reporter=lcov",
"build": "next build",
"start": "next start",
"ts-node": "ts-node --compiler-options \"{\\\"module\\\":\\\"commonjs\\\"}\"",
Expand Down Expand Up @@ -113,7 +114,6 @@
"babel-jest": "^27.2.4",
"babel-plugin-istanbul": "^6.0.0",
"cross-env": "^7.0.3",
"cypress": "^8.3.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
Expand All @@ -123,6 +123,7 @@
"jest": "^27.2.2",
"jest-playwright": "^0.0.1",
"jest-playwright-preset": "^1.7.0",
"kont": "^0.5.1",
"lint-staged": "^11.1.2",
"mockdate": "^3.0.5",
"npm-run-all": "^4.1.5",
Expand Down
34 changes: 34 additions & 0 deletions playwright/booking-pages.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { kont } from "kont";

import { pageProvider } from "./lib/pageProvider";

jest.setTimeout(60e3);

describe("free user", () => {
const ctx = kont()
.useBeforeEach(pageProvider({ path: "/free" }))
.done();

test("only one visible event", async () => {
const { page } = ctx;
await expect(page).toHaveSelector(`[href="/free/30min"]`);
await expect(page).not.toHaveSelector(`[href="/free/60min"]`);
});

// TODO: make sure `/free/30min` is bookable and that `/free/60min` is not
});

describe("pro user", () => {
const ctx = kont()
.useBeforeEach(pageProvider({ path: "/pro" }))
.done();

test("pro user's page has at least 2 visible events", async () => {
const { page } = ctx;
const $eventTypes = await page.$$("[data-testid=event-types] > *");

expect($eventTypes.length).toBeGreaterThanOrEqual(2);
});

// TODO: make sure `/free/30min` is bookable and that `/free/60min` is not
});
Loading

0 comments on commit dc4331e

Please sign in to comment.