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: Add jest testsuite with xmltest cases #112

Merged
merged 27 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a8bfc1e
test: Add jest testsuite with `xmltest` cases
karfau Aug 21, 2020
ad88291
style: Tell git(hub) to show diff for snapshot files
karfau Sep 4, 2020
5124cbf
test: Only run jest for stryker but using commandRunner
karfau Aug 21, 2020
e351f18
test: Drop `files` from stryker config
karfau Sep 11, 2020
f630919
chore: Drop `.gitattributes`
karfau Sep 11, 2020
f50ef64
test: Fix "binary" chars in snapshots and minimize snapshots
karfau Sep 11, 2020
420cfc5
test: Revert jest and stryker config changes
karfau Sep 11, 2020
c81e331
Merge remote-tracking branch 'upstream/master' into jest-xmltest
karfau Sep 11, 2020
243328f
chore: Update xmltest devDependency
karfau Sep 11, 2020
42c986e
cleanup: add semicolons
brodybits Sep 14, 2020
9f3c197
cleanup: remove an extra blank line
brodybits Sep 14, 2020
9c22168
cleanup: add blank lines
brodybits Sep 14, 2020
8faf231
nit: refactor to remove `let`
brodybits Sep 14, 2020
8ec005e
nit: plural snapshots in comment
brodybits Sep 14, 2020
4a2f1e8
remove expected from test snapshots
brodybits Sep 14, 2020
32d9503
rename parameter, etc.
brodybits Sep 14, 2020
b6b84a0
further minimize snapshots
brodybits Sep 14, 2020
e03ad8d
nit: add semicolons to test/get-test-parser.js
brodybits Sep 14, 2020
85d8c41
chore: Update xmltest devDependency
karfau Sep 14, 2020
cc3ef75
test: Restore adding `actual`, and `expected` when different
karfau Sep 14, 2020
e40c15e
rename test/xmltest/minimize-snapshot.js -> test/xmltest/generate-sna…
brodybits Sep 14, 2020
3e6da95
remove semicolons from test/xmltest
brodybits Sep 14, 2020
086e4de
update const variable names in generate-snapshot.js
brodybits Sep 14, 2020
ddefe97
apply some Prettier formatting in test/xmltest
brodybits Sep 15, 2020
25074c1
apply some Prettier formatting in test/get-test-parser.js
brodybits Sep 15, 2020
14c94eb
chore: Update xmltest devDependency (from npm instead of github)
karfau Sep 15, 2020
e39f4f5
cleanup: add blank line to test/get-test-parser.js
brodybits Sep 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
; jest snapshots can and should show in diff, since they are not binary
*.test.js.snap diff
11 changes: 6 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ module.exports = {
// rootDir: undefined,

// A list of paths to directories that Jest should use to search for files in
// roots: [
// "<rootDir>"
// ],
roots: [
// prevents jest from looking for tests in other directories (e.g. leftover `.stryker-tmp`)
"test"
],

// Allows you to use a custom runner instead of Jest's default test runner
// runner: "jest-runner",
Expand Down Expand Up @@ -156,8 +157,8 @@ module.exports = {

// The regexp pattern or array of patterns that Jest uses to detect test files
testRegex: [
/\.test\.js?$/
],
/test\/.*\.test\.js$/
],
karfau marked this conversation as resolved.
Show resolved Hide resolved

// This option allows the use of a custom results processor
// testResultsProcessor: undefined,
Expand Down
135 changes: 109 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@
"dom-js": "0.0.9",
"eslint": "^7.7.0",
"eslint-plugin-es5": "^1.5.0",
"get-stream": "^6.0.0",
"jest": "^26.4.2",
"nodemon": "^2.0.4",
"npm-run-all": "^4.1.5",
"vows": "^0.8.3"
"vows": "^0.8.3",
"xmltest": "github:karfau/xmltest#v1.0.1",
"yauzl": "^2.10.0"
},
"maintainers": [
{
Expand Down
8 changes: 6 additions & 2 deletions stryker.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
},
"coverageAnalysis": "all",
"commandRunner": {
"command": "npm run test:unit"
}
"command": "jest"
},
"files": [
"test/**/*.test.js", "test/get-test-parser.js", "lib/*.js", "package.json", "jest.config.js"
],
"timeoutMS": 15000
}
39 changes: 39 additions & 0 deletions test/get-test-parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
var {DOMParser} = require('../lib/dom-parser')

/**
* @typedef ErrorLevel {'warn' | 'error' | 'fatalError'}
*/
/**
* Helper method for configuring an instance of DOMParser.
* Calling it without any arguments allows to assert on `errors` after using the parser.
* every field of the first argument is options and allows to specify test specific behavior.
* - `errorHandler`: The `locator` to pass to DOMParser constructor options,
* default stores a list of all entries per `key` in `errors` and does not log or throw.
* - `errors`: the object for the `errorHandler` to use,
* is also returned with the same name for later assertions,
* default is an empty object
* - `locator`: The `locator` to pass to DOMParser constructor options,
* default is an empty object
*
* @param options {{
* errorHandler?: function (key: ErrorLevel, msg: string)
* | Partial<Record<ErrorLevel, function(msg:string)>>,
* errors?: Partial<Record<ErrorLevel, string[]>>,
* locator?: Object
* }}
* @returns {{parser: DOMParser, errors: Partial<Record<ErrorLevel, string[]>>}}
*/
function getTestParser ({errorHandler, errors = {}, locator = {}} = {}) {
errorHandler = errorHandler || ((key, msg) => {
if (!errors[key]) errors[key] = []
errors[key].push(msg)
})
return {
errors,
parser: new DOMParser({errorHandler, locator})
}
}

module.exports = {
getTestParser: getTestParser
}
Binary file added test/xmltest/__snapshots__/not-wf.test.js.snap
Binary file not shown.