-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add support for doing snapshot testing
Snapshot testing is one of the idiomatic way of producing tests while building a parser. Our snapshot tests will be of two types a.) Dehydrated ApiDOM snapshot testing Best for keeping track of data and metadata encoded within ApiDOM. b.) S-expresssion representation of ApiDOM Best for checking if semantics of ApiDOM Tree are correct. Closes #432
- Loading branch information
Showing
9 changed files
with
1,630 additions
and
293 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
apidom/packages/apidom-ns-asyncapi-2-0/test/mocha-bootstrap.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
require('@babel/register')({ extensions: ['.js', '.ts'], rootMode: 'upward' }); | ||
|
||
const chai = require('chai'); | ||
const { jestSnapshotPlugin, addSerializer } = require('mocha-chai-jest-snapshot'); | ||
|
||
const jestApiDOMSerializer = require('../../../scripts/jest-serializer-apidom'); | ||
const jestStringSerializer = require('../../../scripts/jest-serializer-string'); | ||
|
||
chai.use(jestSnapshotPlugin()); | ||
addSerializer(jestApiDOMSerializer); | ||
addSerializer(jestStringSerializer); |
40 changes: 40 additions & 0 deletions
40
apidom/packages/apidom-ns-asyncapi-2-0/test/refractor/__snapshots__/index.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`refractor given generic ApiDOM object in AsyncApi 2.0 shape should refract to AsyncApi 2.0 Element 1`] = ` | ||
{ | ||
"element": "asyncApi2_0", | ||
"meta": { | ||
"classes": { | ||
"element": "array", | ||
"content": [ | ||
{ | ||
"element": "string", | ||
"content": "api" | ||
} | ||
] | ||
} | ||
}, | ||
"content": [ | ||
{ | ||
"element": "member", | ||
"content": { | ||
"key": { | ||
"element": "string", | ||
"content": "asyncapi" | ||
}, | ||
"value": { | ||
"element": "asyncApiVersion", | ||
"content": "2.0.0" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
`; | ||
|
||
exports[`refractor given generic ApiDOM object in AsyncApi 2.0 shape should refract to semantic ApiDOM tree 1`] = ` | ||
(AsyncApi2_0Element | ||
(MemberElement | ||
(StringElement) | ||
(AsyncApiVersionElement))) | ||
`; |
15 changes: 10 additions & 5 deletions
15
apidom/packages/apidom-ns-asyncapi-2-0/test/refractor/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const { isElement, dehydrate } = require('../packages/apidom'); | ||
|
||
module.exports = { | ||
test: isElement, | ||
print: (val) => JSON.stringify(dehydrate(val), null, 2), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { identity } = require('ramda'); | ||
const { isString } = require('ramda-adjunct'); | ||
|
||
module.exports = { | ||
test: isString, | ||
print: identity, | ||
}; |