Skip to content
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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"test": "npm-run-all --parallel test:unit test:testcafe",
"semantic-release": "semantic-release"
},
"files": [ "dist" ],
"files": [
"dist"
],
"keywords": [],
"author": "",
"license": "ISC",
Expand Down
17 changes: 13 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
/* eslint-disable no-new-func */
import fs from 'fs'
import path from 'path'
import {ClientFunction, Selector} from 'testcafe'
import {queries} from 'dom-testing-library'
import { ClientFunction, Selector } from 'testcafe'
import { queries } from 'dom-testing-library'

const LIBRARY_UMD_PATH = path.join(
'./node_modules',
Expand All @@ -20,11 +20,11 @@ export const addTestcafeTestingLibrary = async t => {
window.TestCafeTestingLibrary = {}
},
{
dependencies: {script: LIBRARY_UMD_CONTENT},
dependencies: { script: LIBRARY_UMD_CONTENT },
},
)

await inject.with({boundTestRun: t})()
await inject.with({ boundTestRun: t })()
}

Object.keys(queries).forEach(queryName => {
Expand Down Expand Up @@ -60,3 +60,12 @@ export const within = async sel => {

return container
}


export const configure = async options => {
await ClientFunction(new Function(
`
window.DomTestingLibrary.configure(${JSON.stringify(options)});
`
))
}
140 changes: 69 additions & 71 deletions test-app/index.html
Original file line number Diff line number Diff line change
@@ -1,74 +1,72 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>testcafe-testing-library</title>
<style>
blockquote {
margin: 0;
border-left: 4px solid grey;
padding-left: 10px;
color: grey;
}
section {
padding: 10px;
}
</style>
</head>
<body>
<blockquote>
No auto-reload after changing this static HTML markup: click
<span title="Run All Tests">↻</span> Run All Tests.
</blockquote>
<section>
<h2>getByPlaceholderText</h2>
<input type="text" placeholder="Placeholder Text" />
</section>
<section>
<h2>getByText</h2>

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>testcafe-testing-library</title>
<style>
blockquote {
margin: 0;
border-left: 4px solid grey;
padding-left: 10px;
color: grey;
}

section {
padding: 10px;
}
</style>
</head>

<body>
<blockquote>
No auto-reload after changing this static HTML markup: click
<span title="Run All Tests">↻</span> Run All Tests.
</blockquote>
<section>
<h2>getByPlaceholderText</h2>
<input type="text" placeholder="Placeholder Text" />
</section>
<section>
<h2>getByText</h2>
<button onclick="this.innerText = 'Button Clicked'">Button Text</button>
<div id="nested">
<h3>getByText within</h3>
<button onclick="this.innerText = 'Button Clicked'">Button Text</button>
<div id="nested">
<h3>getByText within</h3>
<button onclick="this.innerText = 'Button Clicked'">Button Text</button>
</div>
</section>
<section>
<h2>getByLabelText</h2>
<label for="input-labelled-by-id">Label For Input Labelled By Id</label>
<input
type="text"
placeholder="Input Labelled By Id"
id="input-labelled-by-id"
/>
</section>
<section>
<h2>getByAltText</h2>
<img
src="data:image/png;base64,"
alt="Image Alt Text"
onclick="this.style.border = '5px solid red'"
/>
</section>
<section>
<h2>getByTestId</h2>
<img
data-testid="image-with-random-alt-tag"
src="data:image/png;base64,"
onclick="this.style.border = '5px solid red'"
/>
</section>
<section>
<h2>getAllByText</h2>
<button onclick="this.innerText = 'Jackie Kicked'">Jackie Chan 1</button>
<button onclick="this.innerText = 'Jackie Kicked'">Jackie Chan 2</button>
</section>
<!-- Prettier unindents the script tag below -->
<script>
document
.querySelector('[data-testid="image-with-random-alt-tag"]')
.setAttribute("alt", "Image Random Alt Text " + Math.random());
</script>
</body>
</html>
</div>
</section>
<section>
<h2>getByLabelText</h2>
<label for="input-labelled-by-id">Label For Input Labelled By Id</label>
<input type="text" placeholder="Input Labelled By Id" id="input-labelled-by-id" />
</section>
<section>
<h2>getByAltText</h2>
<img src="data:image/png;base64," alt="Image Alt Text" onclick="this.style.border = '5px solid red'" />
</section>
<section>
<h2>getByTestId</h2>
<img data-testid="image-with-random-alt-tag" src="data:image/png;base64,"
onclick="this.style.border = '5px solid red'" />
</section>
<section>
<h2>configure</h2>
<img data-automation-id="image-with-random-alt-tag" src="data:image/png;base64,"
onclick="this.style.border = '5px solid red'" />
</section>
<section>
<h2>getAllByText</h2>
<button onclick="this.innerText = 'Jackie Kicked'">Jackie Chan 1</button>
<button onclick="this.innerText = 'Jackie Kicked'">Jackie Chan 2</button>
</section>
<!-- Prettier unindents the script tag below -->
<script>
document
.querySelector('[data-testid="image-with-random-alt-tag"]')
.setAttribute("alt", "Image Random Alt Text " + Math.random());
</script>
</body>

</html>
16 changes: 16 additions & 0 deletions tests/testcafe/configure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable import/named */
import { configure, getByTestId, addTestcafeTestingLibrary } from '../../src'



// eslint-disable-next-line babel/no-unused-expressions
fixture`configure`.beforeEach(addTestcafeTestingLibrary)
.page`http://localhost:13370`


test('configure', async t => {
await configure({ testIdAttribute: 'data-automation-id' });

await t
.click(getByTestId('image-with-random-alt-tag'))
})
1 change: 1 addition & 0 deletions tests/unit/__snapshots__/selectors.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`exports expected selectors 1`] = `
Array [
"addTestcafeTestingLibrary",
"within",
"configure",
"queryAllByLabelText",
"getAllByLabelText",
"queryByLabelText",
Expand Down