Skip to content

Commit 5e6b199

Browse files
authored
chore: merge next to master (#30)
* feat: add support for client scripts. still using path to node_modules for now, but will add support for module syntax soon. BREAKING CHANGE: removed addTestcafeTestingLibrary * updated testcafe * updated testing-library/dom * build on next * updated to SR 16.beta * removed addTestcafeTestingLibrary from typings
1 parent b63e9c0 commit 5e6b199

File tree

10 files changed

+974
-629
lines changed

10 files changed

+974
-629
lines changed

.testcaferc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"clientScripts": [
3+
"./node_modules/@testing-library/dom/dist/@testing-library/dom.umd.js"
4+
],
25
"src": "tests/testcafe/**/*.js",
36
"browsers": [
47
"chrome:headless",

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ install: npm ci
2525
script: npm run validate
2626
after_success: npx semantic-release
2727
branches:
28-
only: master
28+
only:
29+
- master
30+
- next

package-lock.json

Lines changed: 926 additions & 556 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,25 @@
2626
"license": "ISC",
2727
"dependencies": {
2828
"@babel/runtime": "^7.4.3",
29-
"@testing-library/dom": "^5.0.1",
30-
"testcafe": "^1.1.2"
29+
"@testing-library/dom": "^6.1.0",
30+
"testcafe": "^1.4.1"
3131
},
3232
"devDependencies": {
3333
"eslint": "^5.16.0",
3434
"eslint-plugin-testcafe": "^0.2.1",
3535
"kcd-scripts": "^1.2.1",
3636
"npm-run-all": "^4.1.5",
37-
"semantic-release": "^15.13.3",
37+
"semantic-release": "^16.0.0-beta.22",
3838
"serve": "^11.0.0"
3939
},
4040
"repository": {
4141
"type": "git",
4242
"url": "https://github.com/testing-library/testcafe-testing-library.git"
43+
},
44+
"release": {
45+
"branches": [
46+
"master",
47+
"next"
48+
]
4349
}
4450
}

src/index.js

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,25 @@
11
/* eslint-disable no-eval */
22
/* eslint-disable no-new-func */
3-
import fs from 'fs'
4-
import path from 'path'
53
import { ClientFunction, Selector } from 'testcafe'
64
import { queries } from '@testing-library/dom'
75

8-
const DOM_TESTING_LIBRARY_UMD_PATH = path.join(
9-
require.resolve( '@testing-library/dom' ),
10-
'../../',
11-
'dist/@testing-library/dom.umd.js',
12-
)
13-
const DOM_TESTING_LIBRARY_UMD = fs.readFileSync(DOM_TESTING_LIBRARY_UMD_PATH).toString()
146

157

8+
export async function configureOnce(options) {
9+
const { content } = configure(options);
1610

11+
await new ClientFunction(new Function(content))();
12+
}
13+
14+
export function configure(options) {
1715

18-
export async function configure(options, t) {
1916
const configFunction =
2017
`
2118
window.TestingLibraryDom.configure(${JSON.stringify(options)});
2219
`;
23-
await new ClientFunction(new Function(configFunction))();
24-
25-
if (t) {
26-
t.testRun.injectable.scripts.push('/testcafe-testing-library-config.js');
27-
t.testRun.session.proxy.GET('/testcafe-testing-library-config.js', { content: configFunction, contentType: 'application/x-javascript' })
28-
}
29-
30-
}
31-
32-
export async function addTestcafeTestingLibrary(t) {
33-
// inject for 1st pageload. Then just use injectables for subsequent page loads.
34-
// eslint-disable-next-line
35-
const inject = ClientFunction(
36-
() => {
37-
// eslint-disable-next-line no-undef
38-
window.eval(script)
39-
},
40-
{
41-
dependencies: { script: DOM_TESTING_LIBRARY_UMD },
42-
},
43-
)
44-
45-
await inject.with({ boundTestRun: t })();
46-
47-
//and for subsequent pageloads:
48-
t.testRun.injectable.scripts.push('/dom-testing-library.js');
49-
t.testRun.session.proxy.GET('/dom-testing-library.js', { content: DOM_TESTING_LIBRARY_UMD, contentType: 'application/x-javascript' })
50-
51-
if (addTestcafeTestingLibrary.options) {
52-
await configure(addTestcafeTestingLibrary.options, t);
53-
}
54-
20+
return { content: configFunction };
5521
}
5622

57-
// eslint-disable-next-line no-shadow
58-
addTestcafeTestingLibrary.configure = function configure(options) {
59-
addTestcafeTestingLibrary.options = { ...options };
60-
return addTestcafeTestingLibrary;
61-
}
6223

6324
Object.keys(queries).forEach(queryName => {
6425
module.exports[queryName] = Selector(

tests/testcafe/configure.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/* eslint-disable import/named */
2-
import { configure, getByTestId, getByText, addTestcafeTestingLibrary } from '../../src'
3-
2+
import { configure, configureOnce, getByTestId, getByText } from '../../src'
43

54

65
// eslint-disable-next-line babel/no-unused-expressions
7-
fixture`configure`.beforeEach(addTestcafeTestingLibrary.configure({ testIdAttribute: 'data-automation-id' }))
6+
fixture`configure`.clientScripts(configure({ testIdAttribute: 'data-automation-id' }))
87
.page`http://localhost:13370`
98

109

@@ -21,6 +20,6 @@ test('still works after browser page load', async t => {
2120
})
2221

2322
test('can be used standalone', async t => {
24-
await configure({ testIdAttribute: 'data-other-test-id' });
23+
await configureOnce({ testIdAttribute: 'data-other-test-id' });
2524
await t.click(getByTestId('other-id'));
2625
})

tests/testcafe/selectors.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import {
88
getByTestId,
99
getAllByText,
1010
queryAllByText,
11-
addTestcafeTestingLibrary,
11+
1212
} from '../../src/'
1313

1414
// eslint-disable-next-line babel/no-unused-expressions
15-
fixture`selectors`.beforeEach(addTestcafeTestingLibrary)
15+
fixture`selectors`
1616
.page`http://localhost:13370`
1717

1818
test('getByPlaceHolderText', async t => {
@@ -64,6 +64,11 @@ test('still works after browser page load', async t => {
6464
.expect(getByText('second page').exists).ok()
6565
})
6666

67+
test('still works after reload', async (t) => {
68+
await t.eval(() => location.reload(true));
69+
await t.expect(getByText('getByText').exists).ok();
70+
});
71+
6772
test.skip('getByTestId only throws the error message', async t => {
6873
const testId = 'Some random id'
6974
const errorMessage = `Unable to find an element by: [data-testid="${testId}"]`

tests/testcafe/within.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
import {Selector} from 'testcafe'
2-
import {within, addTestcafeTestingLibrary} from '../../src'
1+
import { Selector } from 'testcafe'
2+
import { within } from '../../src'
33

44
// eslint-disable-next-line babel/no-unused-expressions
5-
fixture`within`.beforeEach(addTestcafeTestingLibrary)
5+
fixture`within`
66
.page`http://localhost:13370`
77

88
test('getByText within container', async t => {
9-
const {getByText} = await within('#nested')
9+
const { getByText } = await within('#nested')
1010
await t
1111
.click(getByText('Button Text'))
1212
.expect(Selector('button').withExactText('Button Clicked').exists)
1313
.ok()
1414
})
1515

1616
test("queryByPlaceholder doesn't find anything", async t => {
17-
const {queryByPlaceholderText} = await within('#nested')
17+
const { queryByPlaceholderText } = await within('#nested')
1818

1919
await t.expect(queryByPlaceholderText('Placeholder Text').exists).notOk()
2020
})
2121

2222
test('quotes in selector', async t => {
23-
const {getByText} = await within('div[id="nested"]')
23+
const { getByText } = await within('div[id="nested"]')
2424

2525
await t
2626
.click(getByText('Button Text'))

tests/unit/__snapshots__/selectors.test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
exports[`exports expected selectors 1`] = `
44
Array [
5+
"configureOnce",
56
"configure",
6-
"addTestcafeTestingLibrary",
77
"within",
88
"queryAllByLabelText",
99
"getAllByLabelText",
@@ -41,8 +41,8 @@ Array [
4141
"getAllByTitle",
4242
"findAllByTitle",
4343
"findByTitle",
44-
"queryByRole",
4544
"queryAllByRole",
45+
"queryByRole",
4646
"getAllByRole",
4747
"getByRole",
4848
"findAllByRole",

typings/index.d.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
import {BoundFunction, IConfig, queries} from '@testing-library/dom';
2-
import {Selector, t} from 'testcafe';
1+
import { BoundFunction, IConfig, queries } from '@testing-library/dom';
2+
import { Selector, t, ClientScript } from 'testcafe';
33

4-
export function addTestcafeTestingLibrary(
5-
testController: typeof t
6-
): Promise<void>;
4+
export function configureOnce(
5+
options: Pick<IConfig, 'testIdAttribute'>
6+
): Promise<void>
77

88
export function configure(
9-
options: Pick<IConfig, 'testIdAttribute'>,
10-
testController: typeof t
11-
): Promise<void>;
9+
options: Pick<IConfig, 'testIdAttribute'>
10+
): ClientScript;
1211

1312
export type TestcafeBoundFunction<T> = (...params: Parameters<BoundFunction<T>>) => Selector;
14-
export type TestcafeBoundFunctions<T> = {[P in keyof T]: TestcafeBoundFunction<T[P]>};
13+
export type TestcafeBoundFunctions<T> = { [P in keyof T]: TestcafeBoundFunction<T[P]> };
1514

1615
export function within(selector: string): Promise<TestcafeBoundFunctions<typeof queries>>;
1716

0 commit comments

Comments
 (0)