-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
478 additions
and
4 deletions.
There are no files selected for viewing
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,8 @@ | ||
{ | ||
"presets": ["@babel/preset-env"], | ||
"env": { | ||
"test": { | ||
"presets": [["@babel/preset-env"]] | ||
} | ||
} | ||
} |
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 @@ | ||
* text=auto eol=lf |
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,2 @@ | ||
.idea | ||
node_modules |
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,9 @@ | ||
{ | ||
"endOfLine": "lf", | ||
"semi": false, | ||
"singleQuote": false, | ||
"tabWidth": 2, | ||
"trailingComma": "es5", | ||
bracketSpacing: true, | ||
jsxBracketSameLine: true | ||
} |
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,30 @@ | ||
language: node_js | ||
cache: npm | ||
notifications: | ||
email: false | ||
node_js: | ||
- 10.0.0 | ||
- 12 | ||
- node | ||
install: | ||
- npm install | ||
script: | ||
- npm run lint | ||
- npx run test | ||
branches: | ||
only: | ||
- master | ||
- beta | ||
|
||
jobs: | ||
include: | ||
# Define the release stage that runs semantic-release | ||
- stage: release | ||
node_js: lts/* | ||
# Advanced: optionally overwrite your default `script` step to skip the tests | ||
# script: skip | ||
deploy: | ||
provider: script | ||
skip_cleanup: true | ||
script: | ||
- npx semantic-release |
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 babelOptions = { | ||
presets: ['@babel/preset-env'], | ||
}; | ||
|
||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
module.exports = require('babel-jest').createTransformer(babelOptions); |
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,8 @@ | ||
module.exports = { | ||
clearMocks: true, | ||
coverageDirectory: "coverage", | ||
testMatch: ['<rootDir>/tests/*.js'], | ||
transform: { | ||
'^.+\\.js?$': `<rootDir>/jest-preprocess.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
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,94 @@ | ||
import { getQueriesForElement, prettyDOM } from "@testing-library/dom" | ||
import Twig from "twig" | ||
import fs from "fs" | ||
import "@babel/polyfill" | ||
import DrupalAttribute from "drupal-attribute" | ||
|
||
const mountedContainers = new Set() | ||
|
||
if (typeof afterEach === "function") { | ||
afterEach(cleanup) | ||
} | ||
|
||
async function render(twigFile, context = {}, namespaces = {}) { | ||
const baseElement = document.body | ||
const container = baseElement.appendChild(document.createElement("div")) | ||
|
||
// Add it to the mounted containers to cleanup. | ||
mountedContainers.add(container) | ||
|
||
container.innerHTML = await loadTemplate(twigFile, context, namespaces) | ||
|
||
return { | ||
container, | ||
baseElement, | ||
debug: (el = baseElement, maxLength, options) => | ||
Array.isArray(el) | ||
? // eslint-disable-next-line no-console | ||
el.forEach((e) => console.log(prettyDOM(e, maxLength, options))) | ||
: // eslint-disable-next-line no-console, | ||
console.log(prettyDOM(el, maxLength, options)), | ||
...getQueriesForElement(baseElement), | ||
} | ||
} | ||
|
||
const loadTemplate = async (file, context = {}, namespaces) => { | ||
Twig.registryReset = () => { | ||
Twig.Templates.registry = {} | ||
} | ||
|
||
Twig.cache(false) | ||
Twig.extendFunction("create_attribute", (value) => new DrupalAttribute(value)) | ||
Twig.twigAsync = (options) => { | ||
return new Promise((resolve, reject) => { | ||
options.load = resolve | ||
options.error = reject | ||
options.async = true | ||
options.autoescape = false | ||
options.namespaces = namespaces | ||
|
||
if (options.data || options.ref) { | ||
try { | ||
resolve(Twig.twig(options)) | ||
} catch (error) { | ||
reject(error) | ||
} | ||
} else { | ||
fs.readFile(options.path, "utf8", (err, data) => { | ||
if (err) { | ||
reject(new Error(`Unable to find template file ${options.path}`)) | ||
return | ||
} | ||
options.load = (template) => { | ||
template.rawMarkup = data | ||
resolve(template) | ||
} | ||
Twig.twig(options) | ||
}) | ||
} | ||
}) | ||
} | ||
return Twig.twigAsync({ | ||
path: file, | ||
}).then((template) => { | ||
context.attributes = new DrupalAttribute() | ||
return template.render(context) | ||
}) | ||
} | ||
|
||
function cleanup() { | ||
mountedContainers.forEach(cleanupContainer) | ||
} | ||
|
||
function cleanupContainer(container) { | ||
if (container.parentNode === document.body) { | ||
document.body.removeChild(container) | ||
} | ||
mountedContainers.delete(container) | ||
} | ||
|
||
// just re-export everything from dom-testing-library | ||
export * from "@testing-library/dom" | ||
export { render, cleanup } | ||
|
||
/* eslint func-name-matching:0 */ |
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,192 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Test library by testing an accordion Can be initially rendered closed: First expand 1`] = ` | ||
<details | ||
class="accordion accordion--open" | ||
open="" | ||
> | ||
<summary | ||
aria-expanded="true" | ||
aria-pressed="true" | ||
class="accordion__title" | ||
> | ||
Accordion title | ||
</summary> | ||
<div | ||
class="accordion__content" | ||
> | ||
<p> | ||
Cras quis nulla commodo, aliquam lectus sed, blandit augue. Cras ullamcorper bibendum bibendum. Duis tincidunt urna non pretium porta. Nam condimentum vitae ligula vel ornare. Phasellus. | ||
</p> | ||
</div> | ||
</details> | ||
`; | ||
|
||
exports[`Test library by testing an accordion Can be initially rendered closed: Initial render 1`] = ` | ||
<details | ||
class="accordion" | ||
> | ||
<summary | ||
class="accordion__title" | ||
> | ||
Accordion title | ||
</summary> | ||
<div | ||
class="accordion__content" | ||
> | ||
<p> | ||
Cras quis nulla commodo, aliquam lectus sed, blandit augue. Cras ullamcorper bibendum bibendum. Duis tincidunt urna non pretium porta. Nam condimentum vitae ligula vel ornare. Phasellus. | ||
</p> | ||
</div> | ||
</details> | ||
`; | ||
|
||
exports[`Test library by testing an accordion Can be initially rendered closed: Re-collapse 1`] = ` | ||
<details | ||
class="accordion" | ||
> | ||
<summary | ||
aria-expanded="false" | ||
aria-pressed="false" | ||
class="accordion__title" | ||
> | ||
Accordion title | ||
</summary> | ||
<div | ||
class="accordion__content" | ||
> | ||
<p> | ||
Cras quis nulla commodo, aliquam lectus sed, blandit augue. Cras ullamcorper bibendum bibendum. Duis tincidunt urna non pretium porta. Nam condimentum vitae ligula vel ornare. Phasellus. | ||
</p> | ||
</div> | ||
</details> | ||
`; | ||
|
||
exports[`Test library by testing an accordion Can be initially rendered open: First collapse 1`] = ` | ||
<details | ||
class="accordion" | ||
> | ||
<summary | ||
aria-expanded="false" | ||
aria-pressed="false" | ||
class="accordion__title" | ||
> | ||
Accordion title | ||
</summary> | ||
<div | ||
class="accordion__content" | ||
> | ||
<p> | ||
Cras quis nulla commodo, aliquam lectus sed, blandit augue. Cras ullamcorper bibendum bibendum. Duis tincidunt urna non pretium porta. Nam condimentum vitae ligula vel ornare. Phasellus. | ||
</p> | ||
</div> | ||
</details> | ||
`; | ||
|
||
exports[`Test library by testing an accordion Can be initially rendered open: Initial render 1`] = ` | ||
<details | ||
class="accordion accordion--open" | ||
open="" | ||
> | ||
<summary | ||
class="accordion__title" | ||
> | ||
Accordion title | ||
</summary> | ||
<div | ||
class="accordion__content" | ||
> | ||
<p> | ||
Cras quis nulla commodo, aliquam lectus sed, blandit augue. Cras ullamcorper bibendum bibendum. Duis tincidunt urna non pretium porta. Nam condimentum vitae ligula vel ornare. Phasellus. | ||
</p> | ||
</div> | ||
</details> | ||
`; | ||
|
||
exports[`Test library by testing an accordion Can be initially rendered open: Re-open 1`] = ` | ||
<details | ||
class="accordion accordion--open" | ||
open="" | ||
> | ||
<summary | ||
aria-expanded="true" | ||
aria-pressed="true" | ||
class="accordion__title" | ||
> | ||
Accordion title | ||
</summary> | ||
<div | ||
class="accordion__content" | ||
> | ||
<p> | ||
Cras quis nulla commodo, aliquam lectus sed, blandit augue. Cras ullamcorper bibendum bibendum. Duis tincidunt urna non pretium porta. Nam condimentum vitae ligula vel ornare. Phasellus. | ||
</p> | ||
</div> | ||
</details> | ||
`; |
Oops, something went wrong.