Skip to content

Commit

Permalink
fix: nightwatch integration (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
cexbrayat authored Nov 27, 2023
1 parent 8b6c2cd commit 5c4926e
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 49 deletions.
9 changes: 5 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 18 additions & 5 deletions scripts/test.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#!/usr/bin/env zx
import 'zx/globals'

// Vitest would otherwise enable watch mode by default.
process.env.CI = '1'

const playgroundDir = path.resolve(__dirname, '../playground/')
let projects = fs
.readdirSync(playgroundDir, { withFileTypes: true })
Expand All @@ -21,7 +18,13 @@ for (const projectName of projects) {
cd(path.resolve(playgroundDir, projectName))
const packageJSON = require(path.resolve(playgroundDir, projectName, 'package.json'))

console.log(`Building ${projectName}`)
console.log(`
#####
Building ${projectName}
#####
`)
await $`pnpm build`

if ('@playwright/test' in packageJSON.devDependencies) {
Expand All @@ -35,6 +38,16 @@ for (const projectName of projects) {

if ('test:unit' in packageJSON.scripts) {
console.log(`Running unit tests in ${projectName}`)
await $`pnpm test:unit`
if (projectName.includes('vitest') || projectName.includes('with-tests')) {
// Vitest would otherwise enable watch mode by default.
await $`CI=1 pnpm test:unit`
} else {
await $`pnpm test:unit`
}
}

if ('type-check' in packageJSON.scripts) {
console.log(`Running type-check in ${projectName}`)
await $`pnpm type-check`
}
}
2 changes: 1 addition & 1 deletion template/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
},
"devDependencies": {
"@vitejs/plugin-vue": "^4.5.0",
"vite": "^5.0.1"
"vite": "^5.0.2"
}
}
5 changes: 4 additions & 1 deletion template/config/nightwatch-ct/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"scripts": {
"test:unit": "nightwatch src/components/**/__tests__/*"
"test:unit": "nightwatch src/**/__tests__/*"
},
"dependencies": {
"vue": "^3.3.8"
},
"devDependencies": {
"@vue/test-utils": "^2.4.2"
}
}
5 changes: 3 additions & 2 deletions template/config/nightwatch/nightwatch.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ module.exports = {
plugins: ['@nightwatch/vue'],

// See https://nightwatchjs.org/guide/concepts/test-globals.html#external-test-globals
globals_path: 'nightwatch/globals.js',
globals_path: '',

vite_dev_server: {
start_vite: false
start_vite: true,
port: process.env.CI ? 4173 : 5173
},

webdriver: {},
Expand Down
23 changes: 0 additions & 23 deletions template/config/nightwatch/nightwatch/globals.js

This file was deleted.

5 changes: 2 additions & 3 deletions template/config/nightwatch/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scripts": {
"test:e2e": "nightwatch tests/e2e"
"test:e2e": "nightwatch tests/e2e/*"
},
"devDependencies": {
"nightwatch": "^3.3.2",
Expand All @@ -9,7 +9,6 @@
"@types/nightwatch": "^2.3.28",
"geckodriver": "^4.2.1",
"chromedriver": "^119.0.0",
"ts-node": "^10.9.1",
"wait-on": "^7.2.0"
"ts-node": "^10.9.1"
}
}
5 changes: 1 addition & 4 deletions template/config/nightwatch/tests/e2e/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ describe('My First Test', function () {
})

it('visits the app root url', function () {
browser.assert
.textContains('.green', 'You did it!')
.assert.elementHasCount('.wrapper nav a', 2)
.strictClick('.wrapper nav a:last-child')
browser.assert.textContains('.green', 'You did it!')
})

after((browser) => browser.end())
Expand Down
3 changes: 2 additions & 1 deletion template/tsconfig/nightwatch/nightwatch/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
"compilerOptions": {
"target": "ESNext",
"module": "commonjs",
"moduleResolution": "node",
"composite": true,
"rootDir": "../",
"lib": ["ESNext", "dom"],
"types": ["nightwatch"]
},
"include": ["../node_modules/@nightwatch/**/*", "../src/components/**/*", "../tests/e2e/**/*"],
"ts-node": {
"files": true
"transpileOnly": true
},
"files": ["nightwatch.d.ts"]
}
6 changes: 1 addition & 5 deletions utils/filterList.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
export const FILES_TO_FILTER = [
'nightwatch.e2e.conf.js',
'nightwatch.component.conf.js',
'globals.js'
]
export const FILES_TO_FILTER = ['nightwatch.e2e.conf.js', 'nightwatch.component.conf.js']

0 comments on commit 5c4926e

Please sign in to comment.