Skip to content

Commit 0f8702b

Browse files
authored
refactor: use prettier w/ no config (#149)
1 parent b65ac63 commit 0f8702b

16 files changed

+369
-345
lines changed

.eslintrc

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
"plugins": ["testcafe"],
33
"extends": [
44
"./node_modules/kcd-scripts/eslint.js",
5-
"plugin:testcafe/recommended"
6-
]
5+
"plugin:testcafe/recommended",
6+
"prettier"
7+
],
8+
"rules": {
9+
"babel/quotes": "off"
10+
}
711
}

.github/workflows/testcafe-testing-library.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ name: testcafe-testing-library
22
on:
33
push:
44
branches:
5-
- 'master'
6-
- 'alpha'
5+
- "master"
6+
- "alpha"
77
pull_request:
88

99
jobs:
1010
test:
11-
name: 'node ${{ matrix.node }} ${{matrix.browser}} ${{ matrix.os }} '
12-
runs-on: '${{ matrix.os }}'
11+
name: "node ${{ matrix.node }} ${{matrix.browser}} ${{ matrix.os }} "
12+
runs-on: "${{ matrix.os }}"
1313
strategy:
1414
matrix:
1515
os: [ubuntu-latest]
1616
node: [14, 12, 10]
17-
browser: ['chrome:headless', 'firefox:headless']
17+
browser: ["chrome:headless", "firefox:headless"]
1818
steps:
1919
- uses: actions/setup-node@v1
2020
with:
@@ -25,7 +25,7 @@ jobs:
2525
- name: Run TestCafe Tests
2626
uses: DevExpress/testcafe-action@latest
2727
with:
28-
args: '${{ matrix.browser}} tests/testcafe'
28+
args: "${{ matrix.browser}} tests/testcafe"
2929
release:
3030
runs-on: ubuntu-latest
3131
needs: test

.prettierrc

-10
This file was deleted.

.testcaferc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"clientScripts": [
3-
{"module":"@testing-library/dom/dist/@testing-library/dom.umd.js"}
3+
{ "module": "@testing-library/dom/dist/@testing-library/dom.umd.js" }
44
],
55
"src": "tests/testcafe/**/*.ts",
66
"browsers": ["chrome:headless", "firefox:headless"],

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
9595

9696
<!-- markdownlint-enable -->
9797
<!-- prettier-ignore-end -->
98+
9899
<!-- ALL-CONTRIBUTORS-LIST:END -->
99100

100101
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
@@ -127,4 +128,3 @@ MIT
127128
[all-contributors]: https://github.com/all-contributors/all-contributors
128129
[dom-testing-library]: https://github.com/testing-library/dom-testing-library
129130
[testcafe]: https://devexpress.github.io/testcafe/
130-

jest.config.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
const {jest: jestConfig} = require('kcd-scripts/config')
1+
const { jest: jestConfig } = require("kcd-scripts/config");
22

33
const config = Object.assign(jestConfig, {
4-
roots: ['tests/unit'],
5-
testMatch: ['/**/*.test.ts'],
4+
roots: ["tests/unit"],
5+
testMatch: ["/**/*.test.ts"],
66
transform: {
7-
'.ts': 'ts-jest',
7+
".ts": "ts-jest",
88
},
9-
})
9+
});
1010

11-
module.exports = config
11+
module.exports = config;

other/manual-releases.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Number of manual releases: 1
1+
Number of manual releases: 1

package.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
"test:unit": "kcd-scripts test --no-watch --config=jest.config.js",
1111
"test:unit:monorepo": "cd tests/unit && kcd-scripts test --no-watch --config=../../jest.config.js",
1212
"test:testcafe": "testcafe --skip-js-errors",
13-
"validate": "kcd-scripts validate lint,test:unit:monorepo",
13+
"format": "prettier . --write",
14+
"format:check":"prettier . --check",
15+
"validate": "kcd-scripts validate format:check,lint,test:unit:monorepo",
1416
"test": "npm-run-all --parallel test:unit test:unit:monorepo test:testcafe"
1517
},
1618
"files": [
@@ -27,13 +29,15 @@
2729
},
2830
"devDependencies": {
2931
"eslint": "^6.8.0",
32+
"eslint-config-prettier": "^6.11.0",
3033
"eslint-plugin-testcafe": "^0.2.1",
3134
"kcd-scripts": "^5.11.1",
3235
"npm-run-all": "^4.1.5",
36+
"prettier": "^2.0.5",
3337
"semantic-release": "^17.0.7",
38+
"testcafe": "^1.8.4",
3439
"ts-jest": "^25.4.0",
35-
"typescript": "^3.8.3",
36-
"testcafe": "^1.8.4"
40+
"typescript": "^3.8.3"
3741
},
3842
"repository": {
3943
"type": "git",

src/index.ts

+78-76
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import {ClientFunction, Selector} from 'testcafe'
2-
import {queries} from '@testing-library/dom'
1+
import { ClientFunction, Selector } from "testcafe";
2+
import { queries } from "@testing-library/dom";
33
import type {
44
Options,
55
TestcafeBoundFunction,
66
TestcafeBoundFunctions,
7-
} from './types'
7+
} from "./types";
88

99
declare global {
1010
interface Window {
11-
TestingLibraryDom: typeof queries
11+
TestingLibraryDom: typeof queries;
1212
}
1313
}
1414

15-
const SELECTOR_TYPE = Selector('')().constructor.name
15+
const SELECTOR_TYPE = Selector("")().constructor.name;
1616

1717
const withinSelectors = Object.keys(queries).reduce((acc, withinQueryName) => {
1818
return {
@@ -26,109 +26,111 @@ const withinSelectors = Object.keys(queries).reduce((acc, withinQueryName) => {
2626
const args = Array.from(arguments).slice(1);
2727
return window.TestingLibraryDom.within(el).${withinQueryName}.apply(null, args);
2828
`),
29-
}
30-
}, {} as Record<keyof typeof queries, (node: Element, ...methodParams: any[]) => any>)
29+
};
30+
}, {} as Record<keyof typeof queries, (node: Element, ...methodParams: any[]) => any>);
3131

3232
export async function configureOnce(options: Partial<Options>) {
33-
const {content} = configure(options)
33+
const { content } = configure(options);
3434
// @ts-ignore
35-
await ClientFunction(new Function(content))()
35+
await ClientFunction(new Function(content))();
3636
}
3737

3838
export function configure(options: Partial<Options>) {
3939
const configFunction = `
4040
window.TestingLibraryDom.configure(${JSON.stringify(options)});
41-
`
42-
return {content: configFunction}
41+
`;
42+
return { content: configFunction };
4343
}
4444

4545
export function within<T>(
46-
sel: string | Selector | SelectorPromise | TestcafeBoundFunction<T>,
46+
sel: string | Selector | SelectorPromise | TestcafeBoundFunction<T>
4747
): TestcafeBoundFunctions<typeof queries> {
4848
if (sel instanceof Function) {
49-
return within(sel())
49+
return within(sel());
5050
}
5151
if (isSelector(sel)) {
5252
// @ts-ignore
53-
return sel.addCustomMethods(withinSelectors, {returnDOMNodes: true})
54-
} else if (typeof sel === 'string') {
55-
return within(Selector(sel))
53+
return sel.addCustomMethods(withinSelectors, { returnDOMNodes: true });
54+
} else if (typeof sel === "string") {
55+
return within(Selector(sel));
5656
} else {
5757
throw new Error(
58-
`"within" only accepts a query (getBy, queryBy, etc), string or testcafe Selector`,
59-
)
58+
`"within" only accepts a query (getBy, queryBy, etc), string or testcafe Selector`
59+
);
6060
}
6161
}
6262

6363
function isSelector(sel: any): sel is Selector {
64-
return sel.constructor.name === SELECTOR_TYPE
64+
return sel.constructor.name === SELECTOR_TYPE;
6565
}
6666

6767
const bindFunction = <T extends keyof typeof queries>(queryName: T) => {
68-
const query = queryName.replace('find', 'query') as T
68+
const query = queryName.replace("find", "query") as T;
6969
return Selector(
7070
(matcher, ...options) => {
7171
return window.TestingLibraryDom[query](
7272
document.body,
7373
matcher,
74-
...options,
75-
) as Node | Node[] | NodeList | HTMLCollection
74+
...options
75+
) as Node | Node[] | NodeList | HTMLCollection;
7676
},
7777
{
78-
dependencies: {query},
79-
},
80-
)
81-
}
78+
dependencies: { query },
79+
}
80+
);
81+
};
8282

83-
export const getByLabelText = bindFunction('getByLabelText')
84-
export const getAllByLabelText = bindFunction('getAllByLabelText')
85-
export const queryByLabelText = bindFunction('queryByLabelText')
86-
export const queryAllByLabelText = bindFunction('queryAllByLabelText')
87-
export const findByLabelText = bindFunction('findByLabelText')
88-
export const findAllByLabelText = bindFunction('findAllByLabelText')
89-
export const getByPlaceholderText = bindFunction('getByPlaceholderText')
90-
export const getAllByPlaceholderText = bindFunction('getAllByPlaceholderText')
91-
export const queryByPlaceholderText = bindFunction('queryByPlaceholderText')
83+
export const getByLabelText = bindFunction("getByLabelText");
84+
export const getAllByLabelText = bindFunction("getAllByLabelText");
85+
export const queryByLabelText = bindFunction("queryByLabelText");
86+
export const queryAllByLabelText = bindFunction("queryAllByLabelText");
87+
export const findByLabelText = bindFunction("findByLabelText");
88+
export const findAllByLabelText = bindFunction("findAllByLabelText");
89+
export const getByPlaceholderText = bindFunction("getByPlaceholderText");
90+
export const getAllByPlaceholderText = bindFunction("getAllByPlaceholderText");
91+
export const queryByPlaceholderText = bindFunction("queryByPlaceholderText");
9292
export const queryAllByPlaceholderText = bindFunction(
93-
'queryAllByPlaceholderText',
94-
)
95-
export const findByPlaceholderText = bindFunction('findByPlaceholderText')
96-
export const findAllByPlaceholderText = bindFunction('findAllByPlaceholderText')
97-
export const getByText = bindFunction('getByText')
98-
export const getAllByText = bindFunction('getAllByText')
99-
export const queryByText = bindFunction('queryByText')
100-
export const queryAllByText = bindFunction('queryAllByText')
101-
export const findByText = bindFunction('findByText')
102-
export const findAllByText = bindFunction('findAllByText')
103-
export const getByAltText = bindFunction('getByAltText')
104-
export const getAllByAltText = bindFunction('getAllByAltText')
105-
export const queryByAltText = bindFunction('queryByAltText')
106-
export const queryAllByAltText = bindFunction('queryAllByAltText')
107-
export const findByAltText = bindFunction('findByAltText')
108-
export const findAllByAltText = bindFunction('findAllByAltText')
109-
export const getByTitle = bindFunction('getByTitle')
110-
export const getAllByTitle = bindFunction('getAllByTitle')
111-
export const queryByTitle = bindFunction('queryByTitle')
112-
export const queryAllByTitle = bindFunction('queryAllByTitle')
113-
export const findByTitle = bindFunction('findByTitle')
114-
export const findAllByTitle = bindFunction('findAllByTitle')
115-
export const getByDisplayValue = bindFunction('getByDisplayValue')
116-
export const getAllByDisplayValue = bindFunction('getAllByDisplayValue')
117-
export const queryByDisplayValue = bindFunction('queryByDisplayValue')
118-
export const queryAllByDisplayValue = bindFunction('queryAllByDisplayValue')
119-
export const findByDisplayValue = bindFunction('findByDisplayValue')
120-
export const getByRole = bindFunction('getByRole')
121-
export const getAllByRole = bindFunction('getAllByRole')
122-
export const queryByRole = bindFunction('queryByRole')
123-
export const queryAllByRole = bindFunction('queryAllByRole')
124-
export const findByRole = bindFunction('findByRole')
125-
export const findAllByRole = bindFunction('findAllByRole')
126-
export const findAllByDisplayValue = bindFunction('findAllByDisplayValue')
127-
export const getByTestId = bindFunction('getByTestId')
128-
export const getAllByTestId = bindFunction('getAllByTestId')
129-
export const queryByTestId = bindFunction('queryByTestId')
130-
export const queryAllByTestId = bindFunction('queryAllByTestId')
131-
export const findByTestId = bindFunction('findByTestId')
132-
export const findAllByTestId = bindFunction('findAllByTestId')
93+
"queryAllByPlaceholderText"
94+
);
95+
export const findByPlaceholderText = bindFunction("findByPlaceholderText");
96+
export const findAllByPlaceholderText = bindFunction(
97+
"findAllByPlaceholderText"
98+
);
99+
export const getByText = bindFunction("getByText");
100+
export const getAllByText = bindFunction("getAllByText");
101+
export const queryByText = bindFunction("queryByText");
102+
export const queryAllByText = bindFunction("queryAllByText");
103+
export const findByText = bindFunction("findByText");
104+
export const findAllByText = bindFunction("findAllByText");
105+
export const getByAltText = bindFunction("getByAltText");
106+
export const getAllByAltText = bindFunction("getAllByAltText");
107+
export const queryByAltText = bindFunction("queryByAltText");
108+
export const queryAllByAltText = bindFunction("queryAllByAltText");
109+
export const findByAltText = bindFunction("findByAltText");
110+
export const findAllByAltText = bindFunction("findAllByAltText");
111+
export const getByTitle = bindFunction("getByTitle");
112+
export const getAllByTitle = bindFunction("getAllByTitle");
113+
export const queryByTitle = bindFunction("queryByTitle");
114+
export const queryAllByTitle = bindFunction("queryAllByTitle");
115+
export const findByTitle = bindFunction("findByTitle");
116+
export const findAllByTitle = bindFunction("findAllByTitle");
117+
export const getByDisplayValue = bindFunction("getByDisplayValue");
118+
export const getAllByDisplayValue = bindFunction("getAllByDisplayValue");
119+
export const queryByDisplayValue = bindFunction("queryByDisplayValue");
120+
export const queryAllByDisplayValue = bindFunction("queryAllByDisplayValue");
121+
export const findByDisplayValue = bindFunction("findByDisplayValue");
122+
export const getByRole = bindFunction("getByRole");
123+
export const getAllByRole = bindFunction("getAllByRole");
124+
export const queryByRole = bindFunction("queryByRole");
125+
export const queryAllByRole = bindFunction("queryAllByRole");
126+
export const findByRole = bindFunction("findByRole");
127+
export const findAllByRole = bindFunction("findAllByRole");
128+
export const findAllByDisplayValue = bindFunction("findAllByDisplayValue");
129+
export const getByTestId = bindFunction("getByTestId");
130+
export const getAllByTestId = bindFunction("getAllByTestId");
131+
export const queryByTestId = bindFunction("queryByTestId");
132+
export const queryAllByTestId = bindFunction("queryAllByTestId");
133+
export const findByTestId = bindFunction("findByTestId");
134+
export const findAllByTestId = bindFunction("findAllByTestId");
133135

134-
export * from './types'
136+
export * from "./types";

src/types.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import {Config, BoundFunction} from '@testing-library/dom'
1+
import { Config, BoundFunction } from "@testing-library/dom";
22

3-
export type Options = Pick<Config, 'testIdAttribute'>
3+
export type Options = Pick<Config, "testIdAttribute">;
44

55
export type TestcafeBoundFunction<T> = (
66
...params: Parameters<BoundFunction<T>>
7-
) => SelectorPromise
7+
) => SelectorPromise;
88

99
export type TestcafeBoundFunctions<T> = {
10-
[P in keyof T]: TestcafeBoundFunction<T[P]>
11-
}
10+
[P in keyof T]: TestcafeBoundFunction<T[P]>;
11+
};

0 commit comments

Comments
 (0)