Skip to content

Commit 710a8ac

Browse files
committed
feat: Add qwik add command for Nightwatch.
1 parent d4d0818 commit 710a8ac

File tree

6 files changed

+251
-0
lines changed

6 files changed

+251
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
title: Nightwatch | Integrations
3+
keywords: 'e2e, testing'
4+
contributors:
5+
- garg3133
6+
---
7+
8+
# Nightwatch
9+
10+
[Nightwatch](https://nightwatchjs.org) is an integrated end-to-end testing framework powered by [W3C WebDriver API](https://w3c.github.io/webdriver/), the standard for browser automation.
11+
This allows Nightwatch to run e2e tests against _real browsers_ (not browser engines) on both desktop and mobile platforms.
12+
13+
## Usage
14+
15+
You can add Nightwatch easily by using the following Qwik starter script:
16+
17+
```shell
18+
npm run qwik add nightwatch
19+
```
20+
21+
This command will install `nightwatch` into your project, along with two other dependencies, add a `test.e2e` script to your `package.json`, and create a default configuration file named `nightwatch.conf.cjs`.
22+
It will also add an example test within a newly created `test` folder which can be run against the Qwik starter application.
23+
24+
25+
The previous command adds nightwatch to your dependencies, appends a `test.e2e` command in your `package.json` scripts section and creates a default configuration within the `playwright.config.ts` file on the application root level.
26+
It also adds a new file within a newly created `tests` folder called `example.spec.ts` which contains some simple test cases.
27+
28+
For further reference, please check the [Nightwatch documentation](https://nightwatchjs.org/guide/).

packages/docs/src/routes/docs/menu.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
- [Image Optimization](integrations/image-optimization/index.mdx)
6767
- [Leaflet Map](integrations/leaflet-map/index.mdx)
6868
- [Modular Forms](integrations/modular-forms/index.mdx)
69+
- [Nightwatch](integrations/nightwatch/index.mdx)
6970
- [Nx Monorepos](integrations/nx/index.mdx)
7071
- [OG Image](integrations/og-img/index.mdx)
7172
- [Orama](integrations/orama/index.mdx)
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
// Refer to the online docs for more details:
2+
// https://nightwatchjs.org/gettingstarted/configuration/
3+
//
4+
5+
// _ _ _ _ _ _ _
6+
// | \ | |(_) | | | | | | | |
7+
// | \| | _ __ _ | |__ | |_ __ __ __ _ | |_ ___ | |__
8+
// | . ` || | / _` || '_ \ | __|\ \ /\ / / / _` || __| / __|| '_ \
9+
// | |\ || || (_| || | | || |_ \ V V / | (_| || |_ | (__ | | | |
10+
// \_| \_/|_| \__, ||_| |_| \__| \_/\_/ \__,_| \__| \___||_| |_|
11+
// __/ |
12+
// |___/
13+
14+
module.exports = {
15+
// An array of folders (excluding subfolders) where your tests are located;
16+
// if this is not specified, the test source must be passed as the second argument to the test runner.
17+
src_folders: ['test'],
18+
19+
// See https://nightwatchjs.org/guide/concepts/page-object-model.html
20+
page_objects_path: [],
21+
22+
// See https://nightwatchjs.org/guide/extending-nightwatch/adding-custom-commands.html
23+
custom_commands_path: [],
24+
25+
// See https://nightwatchjs.org/guide/extending-nightwatch/adding-custom-assertions.html
26+
custom_assertions_path: [],
27+
28+
// See https://nightwatchjs.org/guide/extending-nightwatch/adding-plugins.html
29+
plugins: [],
30+
31+
// See https://nightwatchjs.org/guide/concepts/test-globals.html
32+
globals_path: 'nightwatch/globals.js',
33+
34+
baseUrl: 'http://localhost:4173',
35+
36+
webdriver: {},
37+
38+
test_workers: {
39+
enabled: true
40+
},
41+
42+
test_settings: {
43+
default: {
44+
disable_error_log: false,
45+
46+
screenshots: {
47+
enabled: false,
48+
path: 'screens',
49+
on_failure: true
50+
},
51+
52+
desiredCapabilities: {
53+
browserName: 'chrome'
54+
},
55+
56+
webdriver: {
57+
start_process: true,
58+
server_path: ''
59+
},
60+
61+
},
62+
63+
safari: {
64+
desiredCapabilities: {
65+
browserName: 'safari',
66+
alwaysMatch: {
67+
acceptInsecureCerts: false
68+
}
69+
},
70+
webdriver: {
71+
start_process: true,
72+
server_path: ''
73+
}
74+
},
75+
76+
firefox: {
77+
desiredCapabilities: {
78+
browserName: 'firefox',
79+
alwaysMatch: {
80+
acceptInsecureCerts: true,
81+
'moz:firefoxOptions': {
82+
args: [
83+
// '-headless',
84+
// '-verbose'
85+
]
86+
}
87+
}
88+
},
89+
webdriver: {
90+
start_process: true,
91+
server_path: '',
92+
cli_args: [
93+
// very verbose geckodriver logs
94+
// '-vv'
95+
]
96+
}
97+
},
98+
99+
chrome: {
100+
desiredCapabilities: {
101+
browserName: 'chrome',
102+
'goog:chromeOptions': {
103+
// More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/
104+
args: [
105+
//'--no-sandbox',
106+
//'--ignore-certificate-errors',
107+
//'--allow-insecure-localhost',
108+
//'--headless=new'
109+
]
110+
}
111+
},
112+
113+
webdriver: {
114+
start_process: true,
115+
server_path: '',
116+
cli_args: [
117+
// --verbose
118+
]
119+
}
120+
},
121+
122+
edge: {
123+
desiredCapabilities: {
124+
browserName: 'MicrosoftEdge',
125+
'ms:edgeOptions': {
126+
// More info on EdgeDriver: https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium/capabilities-edge-options
127+
args: [
128+
//'--headless=new'
129+
]
130+
}
131+
},
132+
133+
webdriver: {
134+
start_process: true,
135+
server_path: '',
136+
cli_args: [
137+
// --verbose
138+
]
139+
}
140+
},
141+
142+
},
143+
144+
usage_analytics: {
145+
enabled: true,
146+
log_path: './logs/analytics',
147+
client_id: '7adb2ef4-e58a-4d84-be15-0d3983b28f9d'
148+
}
149+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import chalk from 'chalk';
2+
import waitOn from 'wait-on';
3+
import path from 'path';
4+
import { spawn, spawnSync } from 'child_process';
5+
6+
let vitePreview = null;
7+
8+
export default {
9+
async before() {
10+
console.info(chalk.dim(' ℹ Starting Vite preview server...'));
11+
12+
spawnSync(path.resolve('node_modules/.bin/qwik'), ['build', 'preview'], { cwd: process.cwd() });
13+
14+
vitePreview = spawn(path.resolve('node_modules/.bin/vite'), ['preview', '--host'], {
15+
cwd: process.cwd()
16+
});
17+
18+
return waitOn({
19+
resources: [this.settings.baseUrl],
20+
timeout: 5000,
21+
}).then(() => {
22+
console.info(chalk.dim(' ℹ Vite preview server running.'));
23+
});
24+
},
25+
26+
async after() {
27+
if (vitePreview) {
28+
console.info(chalk.dim('\n ℹ Stopping Vite preview server...'));
29+
vitePreview.kill('SIGTERM');
30+
console.info(chalk.dim(' ℹ Vite preview server stopped.'));
31+
}
32+
},
33+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"extends": "../tsconfig",
3+
"compilerOptions": {
4+
"target": "esnext",
5+
"module": "commonjs",
6+
"esModuleInterop": true,
7+
"allowSyntheticDefaultImports": true,
8+
"moduleResolution": "node",
9+
"resolveJsonModule": true,
10+
"skipLibCheck": true,
11+
"allowJs": true,
12+
"forceConsistentCasingInFileNames": true,
13+
"noEmit": true
14+
},
15+
"ts-node": {
16+
"transpileOnly": true
17+
},
18+
"include": ["."]
19+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"description": "Use Nightwatch to run E2E tests into your Qwik app",
3+
"__qwik__": {
4+
"displayName": "Integration: Nightwatch (E2E Test)",
5+
"priority": -10,
6+
"viteConfig": {},
7+
"docs": [
8+
"https://qwik.dev/docs/integrations/nightwatch/",
9+
"https://nightwatchjs.org/guide/",
10+
"https://nightwatchjs.org/guide/quickstarts/create-and-run-a-nightwatch-test.html"
11+
]
12+
},
13+
"devDependencies": {
14+
"nightwatch": "^3.6.3",
15+
"ts-node": "^10.9.2",
16+
"wait-on": "^7.2.0"
17+
},
18+
"scripts": {
19+
"test.e2e": "nightwatch ./test"
20+
}
21+
}

0 commit comments

Comments
 (0)