Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Auto generate tests for QUnit #15

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ parser: "@typescript-eslint/parser"
rules:
jsdoc/require-param: off
jsdoc/require-returns: off
"@typescript-eslint/no-namespace": off
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ jobs:
- run: npm run test:esm
- run: npm run test:features
- run: npm run test:qunit
# - run: npm run test:cjs
- run: npm run test:no:specs
- run: npm run test:cjs
- run: npm run lint:ci
- uses: github/codeql-action/upload-sarif@v2
with:
Expand Down
37 changes: 32 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ If you haven't configured `WebdriverIO` yet, check the official [documentation](
In order to use `QUnit Service` you just need to add it to the `services` list in your `wdio.conf.js` file. The wdio documentation has all information related to the [configuration file](https://webdriver.io/docs/configurationfile):

```js
// wdio.conf.js
export const config = {
// ...
services: ["qunit"],
Expand All @@ -38,21 +39,43 @@ export const config = {

## Usage

Make sure the web server is up and running before executing the tests. `wdio` will not start the web server.

### With .spec or .test files

In your WebdriverIO test, you need to navigate to the QUnit HTML test page, then call `browser.getQUnitResults()`.

```js
describe("QUnit test page", () => {
it("should pass QUnit tests", async () => {
await browser.url("http://localhost:8080/test/unit/unitTests.qunit.html");
const qunitResults = await browser.getQUnitResults();
expect(qunitResults).toBeTruthy();
await browser.getQUnitResults();
});
});
```

It's recommended to have one WebdriverIO test file per QUnit HTML test page. This ensures the tests will run in parallel and fully isolated.

Make sure the web server is up and running before executing the tests. `wdio` will not start the web server.
### Configuration only, no .spec or .test files

If you don't want to create spec/test files, you can pass a list of QUnit HTML files to the configuration and the tests will be automatically generated.

```js
// wdio.conf.js
export const config = {
// ...
baseUrl: 'http://localhost:8080',
services: [
['qunit', {
paths: [
'unit-tests.html',
'integration-tests.html',
'test/qunit.html'
]
}],
// ...
};
```

### Test results

Expand All @@ -69,9 +92,13 @@ Straight forward [example](./examples/openui5-sample-app/) using the well known

- Create a configuration file: [wdio.conf.js](.examples/openui5-sample-app/webapp/test/wdio.conf.js)

- Create a WebdriverIO test file for [unit tests](./examples/openui5-sample-app/webapp/test/unit/unit.test.js) and another for [OPA5 tests](./examples/openui5-sample-app/webapp/test/integration/integration.test.js).
- Tell `wdio` where to find the QUnit test files:

- - Include the QUnit files to the [service configuration](./examples/vanilla-qunit/wdio.no-specs.conf.js)
- - or
- - Create a WebdriverIO test file for [unit tests](./examples/openui5-sample-app/webapp/test/unit/unit.test.js) and another for [OPA5 tests](./examples/openui5-sample-app/webapp/test/integration/integration.test.js)

- The web server must be running before executing the tests.
- The web server must be running before executing the tests

- Run it $ `wdio run ./webapp/test/wdio.conf.js`

Expand Down
6 changes: 2 additions & 4 deletions examples/openui5-sample-app/webapp/test/generic/unit.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
describe("QUnit test page", () => {
describe("QUnit test page", function() {
it("should pass QUnit tests - LOCAL", async () => {
await browser.url("http://localhost:8080/test/generic/qunit.html");
const qunitResults = await browser.getQUnitResults();
expect(qunitResults).toBeTruthy();
expect(qunitResults.status).toEqual("passed"); // In case you want to test the overall QUnit status, not really required
await browser.getQUnitResults();
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
describe("QUnit test page OPA", () => {
describe("QUnit test page OPA", function() {
it("should pass QUnit OPA tests - LOCAL", async () => {
await browser.url("http://localhost:8080/test/integration/opaTests.qunit.html");
const qunitResults = await browser.getQUnitResults();
expect(qunitResults).toBeTruthy();
await browser.getQUnitResults();
});
});
6 changes: 2 additions & 4 deletions examples/openui5-sample-app/webapp/test/unit/unit.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
describe("QUnit test page", () => {
describe("QUnit test page", function() {
it("should pass QUnit tests - LOCAL", async () => {
await browser.url("http://localhost:8080/test/unit/unitTests.qunit.html");
const qunitResults = await browser.getQUnitResults();
expect(qunitResults).toBeTruthy();
expect(qunitResults.status).toEqual("passed"); // In case you want to test the overall QUnit status, not required
await browser.getQUnitResults();
});
});
2 changes: 1 addition & 1 deletion examples/openui5-sample-app/webapp/test/wdio.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const config = {
},
],

logLevel: "error",
logLevel: "warn",
framework: "mocha",
reporters: ["spec"],

Expand Down
3 changes: 2 additions & 1 deletion examples/vanilla-qunit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"private": true,
"type": "module",
"scripts": {
"test": "wdio run wdio.conf.js"
"test": "wdio run wdio.conf.js",
"test-no-specs": "wdio run wdio.no-specs.conf.js"
},
"devDependencies": {
"@wdio/cli": "^8",
Expand Down
22 changes: 6 additions & 16 deletions examples/vanilla-qunit/unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
describe('QUnit test page', () => {
describe('QUnit test page', function() {
it('should pass QUnit tests without modules - LOCAL', async () => {
await browser.url('http://localhost:4567/qunit-no-modules.html');
const qunitResults = await browser.getQUnitResults();
expect(qunitResults).toBeTruthy();
expect(qunitResults.status).toEqual('passed'); // In case you want to test the overall QUnit status, not really required
await browser.getQUnitResults();
});

it('should pass QUnit tests in modules - LOCAL', async () => {
await browser.url('http://localhost:4567/qunit-modules.html');
const qunitResults = await browser.getQUnitResults();
expect(qunitResults).toBeTruthy();
expect(qunitResults.status).toEqual('passed'); // In case you want to test the overall QUnit status, not really required
await browser.getQUnitResults();
});

it('should pass QUnit tests in nested modules- LOCAL', async () => {
await browser.url('http://localhost:4567/qunit-nested-modules.html');
const qunitResults = await browser.getQUnitResults();
expect(qunitResults).toBeTruthy();
expect(qunitResults.status).toEqual('passed'); // In case you want to test the overall QUnit status, not really required
await browser.getQUnitResults();
});

it('should pass QUnit tests all together now - LOCAL', async () => {
await browser.url('http://localhost:4567/qunit-all.html');
const qunitResults = await browser.getQUnitResults();
expect(qunitResults).toBeTruthy();
expect(qunitResults.status).toEqual('passed'); // In case you want to test the overall QUnit status, not really required
await browser.getQUnitResults();
});

it('should pass QUnit tests tag - LOCAL', async () => {
await browser.url('http://localhost:4567/qunit-tag.html');
const qunitResults = await browser.getQUnitResults();
expect(qunitResults).toBeTruthy();
expect(qunitResults.status).toEqual('passed'); // In case you want to test the overall QUnit status, not really required
await browser.getQUnitResults();
});
});
2 changes: 1 addition & 1 deletion examples/vanilla-qunit/wdio.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const config = {
}
],

logLevel: 'error',
logLevel: 'warn',
framework: 'mocha',
reporters: ['spec'],

Expand Down
36 changes: 36 additions & 0 deletions examples/vanilla-qunit/wdio.no-specs.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export const config = {
capabilities: [
{
'browserName': 'chrome',
'goog:chromeOptions': {
args: ['headless', 'disable-gpu']
}
}
],

logLevel: 'warn',
framework: 'mocha',
reporters: ['spec'],

baseUrl: 'http://localhost:4567',
services: [
['qunit', {
paths: [
'qunit-tag.html',
'qunit-modules.html',
'./qunit-no-modules.html'
]
}],
[
'static-server',
{
folders: [{mount: '/', path: './'}]
}
],
'devtools'
],
mochaOpts: {
ui: 'bdd',
timeout: 60000
}
};
6 changes: 6 additions & 0 deletions examples/wdio-cjs/integration.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
describe('QUnit test page OPA', function() {
it('should pass QUnit OPA tests - REMOTE', async () => {
await browser.url('https://ui5.sap.com/test-resources/sap/m/demokit/orderbrowser/webapp/test/integration/opaTests.qunit.html');
await browser.getQUnitResults();
});
});
8 changes: 0 additions & 8 deletions examples/wdio-cjs/integration.test.ts

This file was deleted.

8 changes: 8 additions & 0 deletions examples/wdio-cjs/unit.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
describe('QUnit test page', function() {
it('should pass QUnit tests - REMOTE', async () => {
await browser.url(
'https://ui5.sap.com/test-resources/sap/m/demokit/orderbrowser/webapp/test/unit/unitTests.qunit.html'
);
await browser.getQUnitResults();
});
});
10 changes: 0 additions & 10 deletions examples/wdio-cjs/unit.test.ts

This file was deleted.

4 changes: 2 additions & 2 deletions examples/wdio-cjs/wdio.conf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
exports.config = {
specs: ['./*.test.ts'],
specs: ['./*.test.js'],

capabilities: [
{
Expand All @@ -10,7 +10,7 @@ exports.config = {
}
],

logLevel: 'error',
logLevel: 'warn',
framework: 'mocha',
reporters: ['spec'],

Expand Down
6 changes: 2 additions & 4 deletions examples/wdio-esm/integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
describe('QUnit test page OPA', () => {
describe('QUnit test page OPA', function() {
it('should pass QUnit OPA tests - REMOTE', async () => {
await browser.url('https://ui5.sap.com/test-resources/sap/m/demokit/orderbrowser/webapp/test/integration/opaTests.qunit.html');
const qunitResults = await browser.getQUnitResults();
expect(qunitResults).toBeTruthy();
expect(qunitResults.status).toEqual('passed'); // In case you want to test the overall QUnit status, not really required
await browser.getQUnitResults();
});
});
6 changes: 2 additions & 4 deletions examples/wdio-esm/unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
describe('QUnit test page', () => {
describe('QUnit test page', function() {
it('should pass QUnit tests - REMOTE', async () => {
await browser.url(
'https://ui5.sap.com/test-resources/sap/m/demokit/orderbrowser/webapp/test/unit/unitTests.qunit.html'
);
const qunitResults = await browser.getQUnitResults();
expect(qunitResults).toBeTruthy();
expect(qunitResults.status).toEqual('passed'); // In case you want to test the overall QUnit status, not really required
await browser.getQUnitResults();
});
});
2 changes: 1 addition & 1 deletion examples/wdio-esm/wdio.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const config = {
}
],

logLevel: 'error',
logLevel: 'warn',
framework: 'mocha',
reporters: ['spec'],

Expand Down
7 changes: 2 additions & 5 deletions examples/wdio-features/unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
describe('QUnit test page', () => {
describe('QUnit test page', function() {
it('should pass QUnit tests and get code coverage', async () => {
await browser.url(
'https://ui5.sap.com/test-resources/sap/m/demokit/orderbrowser/webapp/test/unit/unitTests.qunit.html'
);

const qunitResults = await browser.getQUnitResults();
expect(qunitResults).toBeTruthy();
expect(qunitResults.status).toEqual('passed'); // In case you want to test the overall QUnit status, not really required

await browser.getQUnitResults();
const coverage = await browser.getCoverageReport();
expect(coverage?.statements.covered).toBeGreaterThan(0);
});
Expand Down
2 changes: 1 addition & 1 deletion examples/wdio-features/wdio.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const config = {
}
],

logLevel: 'error',
logLevel: 'warn',
framework: 'mocha',
reporters: ['spec'],

Expand Down
Loading
Loading