Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
Add snapshot tests to catch regressions not covered in tests
Browse files Browse the repository at this point in the history
This commit has been cherry picked from its original appearance in #164, with the following changes:

- Include all enketo-core fixtures in preparation for adding benchmarks to establish a performance baseline.
- Temporarily increase the timeout for snapshot tests so that the longer running enketo-core fixtures can generate initial snapshots.
- Restore test shuffling (turning that off was a mistake in the original TypeScript PR).
- Switch the default test reporter to `dot` to improve visibility of progress during test runs (it's still not great, mainly due to performance).
- Move `linkedom` stuff to `/test/shared.ts` as it will only be used in tests.
- Accept updates to `package-lock.json` with SHA-512 integrity hashes.
- Excludes formatting of XML/XSL.

About snapshot serialization:

Snapshots use a custom serializer designed to identify only meaningful differences. This means that a snapshot matches if:

- the value is exactly equal
- the value is equal, apart from insignificant changes to whitespace and/or attribute order

The serialization logic:

1. Manually ensures consistent attribute order (using `linkedom` as a DOM compatibility library, primarily because its types are much better than those for `@xmldom/xmldom`).
2. Uses `prettier` to normalize whitespace.
3. Uses `pretty-format` (`vitest`'s default) for final serialization.

Apart from adding snapshots, tests have been updated to reference `linkedom`'s types (corrected where necessary) and to its behavior (which is semantically equivalent to the previous `@xmldom/xmldom` usage, but more consistent with a real DOM environment).
  • Loading branch information
eyelidlessness committed Feb 6, 2023
1 parent 07718a2 commit 485730c
Show file tree
Hide file tree
Showing 126 changed files with 1,017,253 additions and 90 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/*.xml
**/*.xsl
4 changes: 4 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@
"@typescript-eslint/no-unused-vars": "error",
"no-empty-function": "off",
"@typescript-eslint/no-empty-function": "error",
"no-undef": "off",
"no-redeclare": "off",
"@typescript-eslint/no-redeclare": "error",
"import/no-unresolved": "off",

"import/extensions": [
"error",
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
dist/*
docs/*
test-coverage/*
src/xsl/**
test/**/*.xml
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
"editor.formatOnSave": true
},

// Note: it would be nice to reverse this! But it's currently preventing a *ton* of whitespace diff noise
"[xml]": {
"editor.formatOnSave": false
},
"[xsl]": {
"editor.formatOnSave": false
},

// Code navigation
"javascript.referencesCodeLens.enabled": true
}
244 changes: 225 additions & 19 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,25 @@
],
"dependencies": {
"body-parser": "^1.20.1",
"css.escape": "^1.5.1",
"express": "^4.18.2",
"language-tags": "1.0.5",
"libxslt": "0.10.0",
"linkedom": "^0.14.21",
"prettier": "^2.8.1",
"string-direction": "0.1.x",
"undici": "^5.13.0"
"undici": "^5.13.0",
"xpath-to-css": "^1.1.0"
},
"devDependencies": {
"@prettier/plugin-xml": "^2.2.0",
"@types/css.escape": "^1.5.0",
"@types/express": "^4.17.14",
"@types/node": "^18.11.17",
"@types/prettier": "^2.7.2",
"@typescript-eslint/eslint-plugin": "^5.47.0",
"@typescript-eslint/parser": "^5.47.0",
"@vitest/coverage-istanbul": "^0.26.2",
"@xmldom/xmldom": "^0.7.9",
"chai": "^4.3.7",
"chai-as-promised": "^7.1.1",
"docdash": "^1.2.0",
Expand All @@ -85,7 +91,8 @@
"http-server": "^13.1.0",
"istanbul-reporter-shield-badge": "^1.2.1",
"markdown-eslint-parser": "^1.2.1",
"prettier": "^2.8.1",
"pretty-format": "^29.3.1",
"rimraf": "^3.0.2",
"typescript": "^4.9.4",
"vite": "^4.0.3",
"vite-plugin-node": "^1.0.0",
Expand Down
Loading

0 comments on commit 485730c

Please sign in to comment.