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

Test suite improvements #74

Merged
merged 3 commits into from
Dec 17, 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
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,17 @@ jobs:
- name: Run tests
run: npm run ci

test-move-before:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
cache: 'npm'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm run test-move-before

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/node_modules/
/coverage
/test/chrome-profile
.idea
6 changes: 6 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ npm run ci
```
This will run the tests using Playwright’s headless browser setup across Chrome, Firefox, and WebKit (Safari-adjacent). This is ultimately what gets run in Github Actions to verify PRs.

To run all tests against Chrome with experimental `moveBefore` support added, execute:
```bash
npm run test-move-before
```
This will start headless Chrome in a new profile with the `atomic-move` experimental flag set. This runs in a separate job in CI.

## Running Individual Tests

### Headless Mode
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"scripts": {
"test": "web-test-runner",
"debug": "web-test-runner --manual --open",
"test-move-before": "USE_MOVE_BEFORE=1 web-test-runner",
"ci": "web-test-runner --playwright --browsers chromium firefox webkit",
"amd": "(echo \"define(() => {\n\" && cat src/idiomorph.js && echo \"\nreturn Idiomorph});\") > dist/idiomorph.amd.js",
"cjs": "(cat src/idiomorph.js && echo \"\nmodule.exports = Idiomorph;\") > dist/idiomorph.cjs.js",
Expand Down
6 changes: 1 addition & 5 deletions test/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
describe("Bootstrap test", function(){
setup();

beforeEach(function() {
clearWorkArea();
});

// bootstrap test
it('can morph content to content', function()
{
let btn1 = make('<button>Foo</button>')
Expand Down
6 changes: 1 addition & 5 deletions test/core.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
describe("Core morphing tests", function(){

beforeEach(function() {
clearWorkArea();
});
setup();

it('morphs outerHTML as content properly when argument is null', function()
{
Expand Down Expand Up @@ -460,5 +457,4 @@ describe("Core morphing tests", function(){
}
});


})
5 changes: 1 addition & 4 deletions test/fidelity.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
describe("Tests to ensure that idiomorph merges properly", function(){

beforeEach(function() {
clearWorkArea();
});
setup();

function expectFidelity(actual, expected) {
if (actual.outerHTML !== expected) {
Expand Down
7 changes: 2 additions & 5 deletions test/head.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
describe("Tests to ensure that the head tag merging works correctly", function() {

beforeEach(function () {
clearWorkArea();
});
setup();

it('adds a new element correctly', function () {
let parser = new DOMParser();
Expand Down Expand Up @@ -101,4 +98,4 @@ describe("Tests to ensure that the head tag merging works correctly", function()



});
});
1 change: 0 additions & 1 deletion test/htmx-integration.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
describe("Tests for the htmx integration", function() {

function makeServer(){
var server = sinon.fakeServer.create();
htmx.config.defaultSettleDelay = 0;
Expand Down
11 changes: 10 additions & 1 deletion test/lib/utilities.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
/* Test Utilities */

function setup() {
beforeEach(() => {
if (window.useMoveBefore && !Element.prototype.moveBefore) {
throw new Error('Element.prototype.moveBefore is not available.');
}
clearWorkArea();
});
}

function make(htmlStr) {
let range = document.createRange();
let fragment = range.createContextualFragment(htmlStr);
Expand Down Expand Up @@ -47,4 +56,4 @@ function print(elt) {
let text = document.createTextNode( elt.outerHTML + "\n\n" );
getWorkArea().appendChild(text);
return elt;
}
}
6 changes: 1 addition & 5 deletions test/perf.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
describe("Tests to compare perf with morphdom", function(){

beforeEach(function() {
clearWorkArea();
});

setup();

it('HTML5 Elements Sample Page', function(done)
{
Expand Down
33 changes: 28 additions & 5 deletions web-test-runner.config.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
export default {
nodeResolve: true,
coverage: true,
files: "test/*.js",
import { chromeLauncher } from "@web/test-runner";
import { exec } from "child_process";

let config = {
testRunnerHtml: (testFramework) => `
<!DOCTYPE html>
<html>
<head>
<script src="/node_modules/chai/chai.js"></script>
<script src="/node_modules/chai-dom/chai-dom.js"></script>
<script>should = chai.should()</script>
<script>
should = chai.should();
window.useMoveBefore = ${process.env.USE_MOVE_BEFORE};
</script>
<script src="/test/lib/utilities.js"></script>
<script src="/node_modules/sinon/pkg/sinon.js"></script>

Expand All @@ -29,5 +32,25 @@ export default {
</body>
</html>
`,

nodeResolve: true,
coverage: true,
coverageConfig: {
include: ['src/**/*'],
},
files: "test/*.js",
};

if (process.env.USE_MOVE_BEFORE) {
// configure chrome to use a custom profile directory we control
config.browsers = [
chromeLauncher({ launchOptions: { args: ['--user-data-dir=test/chrome-profile'] } })
]
exec([
'rm -rf test/chrome-profile', // clear profile out from last run
'mkdir -p test/chrome-profile', // create from scratch
`echo '{"browser":{"enabled_labs_experiments":["atomic-move@1"]}}' > test/chrome-profile/Local\\ State`, // enable experiment
].join(" && "));
}

export default config;
Loading