Skip to content
Open
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
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ jobs:
exit 1
fi

test-node:
name: Node Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout Branch
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: "package.json"
cache: "npm"

- name: Install Node Packages
run: npm ci

- name: Run Node Unit Tests
run: npm test

build:
name: Build
runs-on: macos-latest
Expand Down
12 changes: 11 additions & 1 deletion Testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@ Tests are located in the `/tests` folder.

## Local Testing

To run this locally you'll need the browsers installed along with the corresponding driver:
### Local Node.js Unit Testing

You can run the unit tests directly in Node.js using:

```bash
npm run test:node
```

### In-Browser Testing

To run the in-browser tests locally, you'll need the browsers installed along with the corresponding driver:

- [chromedriver](https://chromedriver.chromium.org/getting-started)
- [geckodriver](https://github.com/mozilla/geckodriver/releases)
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"license": "SEE LICENSE IN LICENSE",
"scripts": {
"dev": "node tests/server.mjs",
"lint:check": "eslint **/*.{js,mjs,jsx,ts,tsx}",
"lint:check": "eslint \"**/*.{js,mjs,jsx,ts,tsx}\"",
"lint:fix": "eslint \"**/*.{js,mjs,jsx,ts,tsx}\" --fix",
"pretty:check": "prettier --check ./",
"pretty:fix": "prettier --write ./",
Expand All @@ -29,7 +29,9 @@
"test-e2e:chrome": "node tests/run-end2end.mjs --browser chrome",
"test-e2e:firefox": "node tests/run-end2end.mjs --browser firefox",
"test-e2e:safari": "node tests/run-end2end.mjs --browser safari",
"test-e2e:edge": "node tests/run-end2end.mjs --browser edge"
"test-e2e:edge": "node tests/run-end2end.mjs --browser edge",
"test": "npm run test:node",
"test:node": "mocha --require ./tests/setup-node.mjs \"tests/unittests/*.mjs\""
},
"devDependencies": {
"@babel/core": "^7.21.3",
Expand Down
6 changes: 6 additions & 0 deletions resources/shared/helpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,9 @@ export function forceLayout(body, layoutMode = "getBoundingRectAndElementFromPoi
throw Error(`Invalid layoutMode: ${layoutMode}`);
}
}

export function skipInShell(context) {
if (typeof window === "undefined" || typeof document === "undefined")
// Skip in non-browser environments
context.skip();
}
11 changes: 11 additions & 0 deletions tests/setup-node.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import expect from "expect.js";
import sinon from "sinon";

globalThis.expect = expect;
globalThis.sinon = sinon;

export const mochaHooks = {
afterEach() {
sinon.restore();
},
};
4 changes: 3 additions & 1 deletion tests/unittests/benchmark-runner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BenchmarkRunner } from "../../resources/benchmark-runner.mjs";
import { SuiteRunner } from "../../resources/suite-runner.mjs";
import { StepRunner } from "../../resources/shared/step-runner.mjs";
import { defaultParams } from "../../resources/shared/params.mjs";
import { skipInShell } from "../../resources/shared/helpers.mjs";

function TEST_FIXTURE(name) {
return {
Expand Down Expand Up @@ -35,7 +36,8 @@ describe("BenchmarkRunner", () => {
const { spy, stub, assert } = sinon;
let runner;

before(() => {
before(function () {
skipInShell(this);
runner = new BenchmarkRunner(SUITES_FIXTURE, CLIENT_FIXTURE);
});

Expand Down
Loading