Skip to content

Commit

Permalink
Replace nightwatch with playwright for e2e testing. Remove legacy deps.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrichar1 committed Nov 15, 2023
1 parent a1c7274 commit c3ec62f
Show file tree
Hide file tree
Showing 30 changed files with 357 additions and 5,960 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ jobs:
run: |
yarn
yarn lint
yarn test
yarn unit
yarn e2e
yarn docs
- name: Setup Node.js
Expand Down
11 changes: 0 additions & 11 deletions examples/testapp/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions examples/testapp/babel.config.js

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<link rel="icon" href="<%= BASE_URL %>favicon.ico" />
<title>testapp</title>
</head>
<body>
Expand All @@ -14,6 +13,6 @@
>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
<script type="module" src="/src/main.js"></script>
</body>
</html>
5 changes: 0 additions & 5 deletions examples/testapp/postcss.config.js

This file was deleted.

39 changes: 14 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,46 @@
"description": "Access restructured JSONAPI data from a Vuex Store.",
"author": "Matthew Richardson <M.Richardson@ed.ac.uk>",
"scripts": {
"lint": "eslint .",
"dev": "concurrently --success first --kill-others \"npm:fakeapiserver\" \"vite dev\"",
"docs": "rm -rf docs/; jsdoc -c jsdoc.json",
"e2e": "concurrently --success first --kill-others \"npm:fakeapiserver\" \"vue-cli-service test:e2e --env chrome --headless\"",
"e2e": "playwright test --project 'Google Chrome'",
"fakeapiserver": "node examples/fake-json-api-server.js",
"test": "npm run unit && npm run e2e",
"testapp": "concurrently --kill-others \"npm:fakeapiserver\" \"vue-cli-service serve\"",
"unit": "vitest run"
"lint": "eslint .",
"unit": "vitest run --dir tests/unit"
},
"main": "src/jsonapi-vuex.js",
"files": [
"src/"
],
"dependencies": {
"jsonpath-plus": "^7.2.0",
"lodash": "^4.17.21",
"vitest": "^0.34.6"
"lodash": "^4.17.21"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~5.0.8",
"@vue/cli-plugin-e2e-nightwatch": "~5.0.8",
"@vue/cli-plugin-eslint": "~5.0.8",
"@vue/cli-plugin-vuex": "~5.0.8",
"@vue/cli-service": "~5.0.8",
"@vue/test-utils": "^2.3.1",
"@babel/core": "^7.23.3",
"@babel/eslint-parser": "^7.23.3",
"@playwright/test": "^1.39.0",
"@vitejs/plugin-vue": "^4.4.1",
"axios": "^1.6.2",
"axios-mock-adapter": "^1.22.0",
"@babel/core": "^7.21.0",
"@babel/eslint-parser": "^7.19.1",
"@babel/preset-env": "^7.20.2",
"chai": "^4.3.10",
"chromedriver": "^118.0.0",
"concurrently": "^7.6.0",
"core-js": "^3.29.1",
"eslint": "^8.36.0",
"eslint-config-prettier": "^8.7.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-prettier-vue": "^4.2.0",
"eslint-plugin-vue": "^9.9.0",
"eslint-webpack-plugin": "^4.0.0",
"fake-json-api-server": "^1.6.0",
"geckodriver": "^3.2.0",
"husky": "^8.0.3",
"happy-dom": "^12.10.3",
"jsdoc": "^4.0.2",
"lint-staged": "^13.2.0",
"nightwatch": "^2.6.17",
"prettier": "^2.8.4",
"sinon": "^17.0.1",
"sinon-chai": "^3.7.0",
"vue": "^3.2.47",
"vuex": "^4.1.0",
"webpack": "^5.0.0"
"vite": "^4.4.5",
"vitest": "^0.34.6",
"vue": "^3.3.8",
"vuex": "^4.1.0"
},
"peerDependencies": {
"vue": "^3.0.11",
Expand Down
51 changes: 51 additions & 0 deletions playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { defineConfig } from '@playwright/test'

export default defineConfig({
testDir: './tests/e2e',
testMatch: /.*\.js/,
/* Maximum time one test can run for. */
timeout: 30 * 1000,
expect: {
/**
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 0,
},
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'list',
use: {
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 10000,
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: 'http://localhost:5173',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',

/* Only on CI systems run the tests headless */
headless: !!process.env.CI,
},

/* Run your local dev server before starting the tests */
webServer: {
command: 'yarn dev',
port: 5173,
reuseExistingServer: !process.env.CI,
},
// Google Chrome is pre-installed on Github CI/dev desktops, so use it to avoid 'playwright install' delays
projects: [
{
name: 'Google Chrome',
use: {
channel: 'chrome',
},
},
],
})
Empty file.
Empty file removed tests/e2e/custom-commands/.gitkeep
Empty file.
Empty file removed tests/e2e/globals.js
Empty file.
Empty file removed tests/e2e/page-objects/.gitkeep
Empty file.
79 changes: 0 additions & 79 deletions tests/e2e/specs/test.js

This file was deleted.

80 changes: 80 additions & 0 deletions tests/e2e/vue.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { expect, test } from '@playwright/test'

let page

test.beforeAll(async ({ browser }) => {
page = await browser.newPage()
await page.goto('localhost:5173')
})

test('Has main div', async () => {
expect(await page.locator('#main-div').isVisible()).toBe(true)
})

test('Has h1 title', async () => {
expect(await page.locator('div#main-div > h1')).toHaveText('JSONAPI Vuex Test App')
})

test('Has raw data div', async () => {
expect(await page.locator('#raw_data').isVisible()).toBe(true)
})

test('Has h2 raw title', async () => {
expect(await page.locator('div#raw_data > h2')).toHaveText('Raw Data')
})

test('Has render data div', async () => {
expect(await page.locator('#render_data').isVisible()).toBe(true)
})

test('Has h2 render title', async () => {
expect(await page.locator('div#render_data > h2')).toHaveText('Rendered Data')
})

test('Has initial API data', async () => {
expect(await page.locator('#span_name_1')).toHaveText('sprocket')
expect(await page.locator('#span_color_1')).toHaveText('black')
})

test('Has related objects', async () => {
expect(await page.locator('#rel_span_relname')).toHaveText('widgets')
expect(await page.locator('#rel_span_name')).toHaveText('gear')
expect(await page.locator('#rel_span_color')).toHaveText('blue')
})

test('Has initial API search data', async () => {
expect(await page.locator('#search_name_1')).toHaveText('sprocket')
expect(await page.locator('#search_color_1')).toHaveText('black')
})

test('Inputs exist and have correct values ', async () => {
expect(await page.locator('#patch').isVisible()).toBe(true)
expect(await page.locator('#patch_name')).toHaveValue('sprocket')
expect(await page.locator('#patch_color')).toHaveValue('black')
})

test('Patch values', async () => {
expect(await page.locator('#patch_name').fill('cog'))
expect(await page.locator('#patch_color').fill('red'))
await page.getByRole('button', { name: 'Patch' }).click()
await page.waitForTimeout(1000)
expect(await page.locator('#span_name_1')).toHaveText('cog')
expect(await page.locator('#span_color_1')).toHaveText('red')
})

test('Post new item', async () => {
expect(await page.locator('#post_name').fill('wheel'))
expect(await page.locator('#post_color').fill('green'))
await page.getByRole('button', { name: 'Post' }).click()
await page.waitForTimeout(1000)
expect(await page.locator('#span_name_4')).toHaveText('wheel')
expect(await page.locator('#span_color_4')).toHaveText('green')
})

test('Delete an item', async () => {
expect(await page.locator('#span_name_1').isVisible()).toBe(true)
expect(await page.locator('#delete_id').fill('1'))
await page.getByRole('button', { name: 'Delete' }).click()
await page.waitForTimeout(1000)
expect(await page.locator('#span_name_1').isVisible()).toBe(false)
})
2 changes: 1 addition & 1 deletion tests/unit/actions/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('create', function () {
let jsonapiModule

beforeEach(function () {
[ api ] = makeApi()
;[api] = makeApi()
jsonapiModule = createJsonapiModule(api)
})

Expand Down
3 changes: 1 addition & 2 deletions tests/unit/actions/delete.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { beforeEach, describe, expect, test } from 'vitest'
import sinonChai from 'sinon-chai'
import sinon from 'sinon'
import chai from 'chai'
chai.use(sinonChai)

Expand All @@ -15,7 +14,7 @@ describe('delete', function () {
let jsonWidget1, normWidget1, jsonapiModule, stubContext

beforeEach(function () {
[ api, mockApi ] = makeApi()
;[api, mockApi] = makeApi()
jsonWidget1 = createJsonWidget1()
normWidget1 = createNormWidget1()

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/actions/deleteRelated.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('deleteRelated', function () {
let normWidget1, jsonWidget1, jsonapiModule, stubContext

beforeEach(function () {
[ api, mockApi ] = makeApi()
;[api, mockApi] = makeApi()
normWidget1 = createNormWidget1()
jsonWidget1 = createJsonWidget1()

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/actions/fetch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('fetch', function () {
let jsonapiModule

beforeEach(function () {
[ api ] = makeApi()
;[api] = makeApi()
jsonapiModule = createJsonapiModule(api)
})

Expand Down
5 changes: 2 additions & 3 deletions tests/unit/actions/get.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { beforeEach, describe, expect, test } from 'vitest'
import sinonChai from 'sinon-chai'
import sinon from 'sinon'
import chai from 'chai'
chai.use(sinonChai)

Expand Down Expand Up @@ -37,7 +36,7 @@ describe('get', function () {

beforeEach(function () {
// Mock up a fake axios-like api instance
[ api, mockApi ] = makeApi()
;[api, mockApi] = makeApi()
jsonMachine1 = createJsonMachine1()
normMachine1 = createNormMachine1()
jsonWidget1 = createJsonWidget1()
Expand Down Expand Up @@ -232,4 +231,4 @@ describe('get', function () {
expect(error.response.status).to.equal(500)
}
})
})
})
Loading

0 comments on commit c3ec62f

Please sign in to comment.