Skip to content

Commit 6e46b5a

Browse files
Merge branch 'main' into patch-1
2 parents 51c8ea0 + 13e825c commit 6e46b5a

File tree

10 files changed

+132
-70
lines changed

10 files changed

+132
-70
lines changed

.all-contributorsrc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@
9090
"contributions": [
9191
"code",
9292
"doc",
93-
"test"
93+
"test",
94+
"review"
9495
]
9596
},
9697
{
@@ -111,6 +112,15 @@
111112
"contributions": [
112113
"code"
113114
]
115+
},
116+
{
117+
"login": "benmccann",
118+
"name": "Ben McCann",
119+
"avatar_url": "https://avatars.githubusercontent.com/u/322311?v=4",
120+
"profile": "http://www.benmccann.com",
121+
"contributions": [
122+
"test"
123+
]
114124
}
115125
],
116126
"contributorsPerLine": 7,

.github/workflows/release.yml

Lines changed: 63 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,80 @@ name: CI
33
on:
44
push:
55
branches: [main]
6+
pull_request:
7+
branches: [main]
68

79
jobs:
8-
test:
10+
main:
911
# ignore all-contributors PRs
1012
if: ${{ !contains(github.head_ref, 'all-contributors') }}
11-
12-
runs-on: ubuntu-latest
13-
1413
strategy:
1514
matrix:
1615
node: [10, 12, 14, 16]
17-
16+
runs-on: ubuntu-latest
1817
steps:
19-
- name: Cancel previous runs
20-
uses: styfle/[email protected]
18+
- name: 🛑 Cancel Previous Runs
19+
uses: styfle/[email protected]
20+
21+
- name: ⬇️ Checkout repo
22+
uses: actions/checkout@v3
23+
24+
- name: ⎔ Setup node
25+
uses: actions/setup-node@v3
26+
with:
27+
node-version: ${{ matrix.node }}
2128

22-
- uses: actions/checkout@v2
29+
- name: 📥 Download deps
30+
uses: bahmutov/npm-install@v1
31+
with:
32+
useLockFile: false
2333

24-
- name: Setup nodejs
25-
uses: actions/setup-node@v2
26-
with:
27-
node-version: ${{ matrix.node }}
28-
- name: Install deps & validate
29-
run: npm run setup
34+
- name: ▶️ Run validate script
35+
run: npm run validate
36+
37+
- name: ⬆️ Upload coverage report
38+
uses: codecov/codecov-action@v2
3039

3140
release:
41+
needs: main
3242
runs-on: ubuntu-latest
33-
43+
if:
44+
${{ github.repository == 'testing-library/svelte-testing-library' &&
45+
contains('refs/heads/main,refs/heads/beta,refs/heads/next,refs/heads/alpha',
46+
github.ref) && github.event_name == 'push' }}
3447
steps:
35-
- name: Cancel previous runs
36-
uses: styfle/[email protected]
37-
38-
- uses: actions/checkout@v2
39-
40-
- name: Setup nodejs
41-
uses: actions/setup-node@v2
42-
with:
43-
node-version: 14
44-
- name: Install deps
45-
run: npm install
46-
- name: Build proj
47-
run: npm run build
48-
- name: Update tests, coverage, and release
49-
run: npm run test:update && npx codecov && npx semantic-release
50-
env:
51-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
52-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
- name: 🛑 Cancel Previous Runs
49+
uses: styfle/[email protected]
50+
51+
- name: ⬇️ Checkout repo
52+
uses: actions/checkout@v3
53+
54+
- name: ⎔ Setup node
55+
uses: actions/setup-node@v3
56+
with:
57+
node-version: 16
58+
59+
- name: 📥 Download deps
60+
uses: bahmutov/npm-install@v1
61+
with:
62+
useLockFile: false
63+
64+
- name: 🏗 Run build script
65+
run: npm run build
66+
67+
- name: 🚀 Release
68+
uses: cycjimmy/semantic-release-action@v2
69+
with:
70+
semantic_version: 17
71+
branches: |
72+
[
73+
'+([0-9])?(.{+([0-9]),x}).x',
74+
'main',
75+
'next',
76+
'next-major',
77+
{name: 'beta', prerelease: true},
78+
{name: 'alpha', prerelease: true}
79+
]
80+
env:
81+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
82+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,10 @@ Thanks goes to these people ([emoji key][emojis]):
130130
<td align="center"><a href="https://twitter.com/sebsilbermann"><img src="https://avatars3.githubusercontent.com/u/12292047?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sebastian Silbermann</b></sub></a><br /><a href="https://github.com/testing-library/svelte-testing-library/commits?author=eps1lon" title="Code">💻</a></td>
131131
</tr>
132132
<tr>
133-
<td align="center"><a href="https://github.com/mihar-22"><img src="https://avatars3.githubusercontent.com/u/14304599?s=460&v=4?s=100" width="100px;" alt=""/><br /><sub><b>Rahim Alwer</b></sub></a><br /><a href="https://github.com/testing-library/svelte-testing-library/commits?author=mihar-22" title="Code">💻</a> <a href="https://github.com/testing-library/svelte-testing-library/commits?author=mihar-22" title="Documentation">📖</a> <a href="https://github.com/testing-library/svelte-testing-library/commits?author=mihar-22" title="Tests">⚠️</a></td>
133+
<td align="center"><a href="https://github.com/mihar-22"><img src="https://avatars3.githubusercontent.com/u/14304599?s=460&v=4?s=100" width="100px;" alt=""/><br /><sub><b>Rahim Alwer</b></sub></a><br /><a href="https://github.com/testing-library/svelte-testing-library/commits?author=mihar-22" title="Code">💻</a> <a href="https://github.com/testing-library/svelte-testing-library/commits?author=mihar-22" title="Documentation">📖</a> <a href="https://github.com/testing-library/svelte-testing-library/commits?author=mihar-22" title="Tests">⚠️</a> <a href="https://github.com/testing-library/svelte-testing-library/pulls?q=is%3Apr+reviewed-by%3Amihar-22" title="Reviewed Pull Requests">👀</a></td>
134134
<td align="center"><a href="https://github.com/MirrorBytes"><img src="https://avatars3.githubusercontent.com/u/22119469?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Bob</b></sub></a><br /><a href="https://github.com/testing-library/svelte-testing-library/issues?q=author%3AMirrorBytes" title="Bug reports">🐛</a> <a href="https://github.com/testing-library/svelte-testing-library/commits?author=MirrorBytes" title="Code">💻</a></td>
135135
<td align="center"><a href="https://github.com/ronmerkin"><img src="https://avatars.githubusercontent.com/u/17492527?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ron Merkin</b></sub></a><br /><a href="https://github.com/testing-library/svelte-testing-library/commits?author=ronmerkin" title="Code">💻</a></td>
136+
<td align="center"><a href="http://www.benmccann.com"><img src="https://avatars.githubusercontent.com/u/322311?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ben McCann</b></sub></a><br /><a href="https://github.com/testing-library/svelte-testing-library/commits?author=benmccann" title="Tests">⚠️</a></td>
136137
</tr>
137138
</table>
138139

package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,35 +51,35 @@
5151
"svelte": "3.x"
5252
},
5353
"dependencies": {
54-
"@testing-library/dom": "^7.0.3"
54+
"@testing-library/dom": "^8.1.0"
5555
},
5656
"devDependencies": {
5757
"@babel/cli": "^7.6.2",
5858
"@babel/core": "^7.6.2",
5959
"@babel/plugin-transform-modules-commonjs": "^7.6.0",
6060
"@babel/preset-env": "^7.6.2",
61-
"@commitlint/cli": "^11.0.0",
62-
"@commitlint/config-conventional": "^11.0.0",
61+
"@commitlint/cli": "^13.1.0",
62+
"@commitlint/config-conventional": "^13.1.0",
6363
"@testing-library/jest-dom": "^5.0.2",
64-
"@types/jest": "^26.0.0",
64+
"@types/jest": "^27.0.0",
6565
"all-contributors-cli": "^6.9.0",
6666
"babel-eslint": "^10.0.3",
67-
"babel-jest": "^26.0.1",
67+
"babel-jest": "^27.0.6",
6868
"doctoc": "^2.0.0",
6969
"eslint": "^7.2.0",
7070
"eslint-config-standard": "^16.0.0",
7171
"eslint-plugin-import": "^2.18.2",
7272
"eslint-plugin-node": "^11.0.0",
73-
"eslint-plugin-promise": "^4.2.1",
73+
"eslint-plugin-promise": "^5.1.0",
7474
"eslint-plugin-simple-import-sort": "^7.0.0",
7575
"eslint-plugin-svelte3": "^3.0.0",
76-
"husky": "^4.0.9",
77-
"jest": "^26.0.1",
78-
"lint-staged": "^10.0.0",
76+
"husky": "^7.0.1",
77+
"jest": "^27.0.0",
78+
"lint-staged": "^11.1.1",
7979
"npm-run-all": "^4.1.5",
8080
"prettier": "^2.0.1",
8181
"svelte": "^3.0.0",
82-
"svelte-jester": "^1.0.3"
82+
"svelte-jester": "^2.1.4"
8383
},
8484
"husky": {
8585
"hooks": {
@@ -118,6 +118,7 @@
118118
"setupFilesAfterEnv": [
119119
"@testing-library/jest-dom/extend-expect"
120120
],
121+
"testEnvironment": "jsdom",
121122
"transform": {
122123
"^.+\\.js$": "babel-jest",
123124
"^.+\\.svelte$": "svelte-jester",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`auto-cleanup-skip second 1`] = `"<div><h1 data-testid=\\"test\\">Hello world!</h1> <button>Button</button></div>"`;
3+
exports[`auto-cleanup-skip second 1`] = `"<div><h1 data-testid=\\"test\\">Hello world!</h1> <div>we have undefined</div> <button>Button</button></div>"`;

src/__tests__/__snapshots__/render.test.js.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ exports[`render should accept svelte component options 1`] = `
1111
!
1212
</h1>
1313
14+
<div>
15+
we have context
16+
</div>
17+
1418
<button>
1519
Button
1620
</button>

src/__tests__/fixtures/Comp.svelte

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<script>
2+
import { getContext } from 'svelte'
3+
24
export let name
35
46
let buttonText = 'Button'
57
8+
const contextName = getContext('name')
9+
610
function handleClick () {
711
buttonText = 'Button Clicked'
812
}
@@ -12,4 +16,6 @@
1216

1317
<h1 data-testid="test">Hello {name}!</h1>
1418

19+
<div>we have {contextName}</div>
20+
1521
<button on:click={handleClick}>{buttonText}</button>

src/__tests__/multi-base.test.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,8 @@ import { render } from '..'
22
import Comp from './fixtures/Comp'
33

44
describe('multi-base', () => {
5-
let treeA
6-
let treeB
7-
8-
beforeAll(() => {
9-
treeA = document.createElement('div')
10-
treeB = document.createElement('div')
11-
document.body.appendChild(treeA)
12-
document.body.appendChild(treeB)
13-
})
14-
15-
afterAll(() => {
16-
treeA.parentNode.removeChild(treeA)
17-
treeB.parentNode.removeChild(treeB)
18-
})
5+
const treeA = document.createElement('div')
6+
const treeB = document.createElement('div')
197

208
test('container isolates trees from one another', () => {
219
const { getByText: getByTextInA } = render(Comp, {

src/__tests__/render.test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ describe('render', () => {
5353
const { container } = stlRender(Comp, {
5454
target,
5555
anchor: div,
56-
props: { name: 'World' }
56+
props: { name: 'World' },
57+
context: new Map([['name', 'context']])
5758
})
5859
expect(container).toMatchSnapshot()
5960
})
@@ -75,4 +76,15 @@ describe('render', () => {
7576

7677
expect(getByText('Hello World!')).toBeInTheDocument()
7778
})
79+
80+
test("accept the 'context' option", () => {
81+
const { getByText } = stlRender(Comp, {
82+
props: {
83+
name: 'Universe'
84+
},
85+
context: new Map([['name', 'context']])
86+
})
87+
88+
expect(getByText('we have context')).toBeInTheDocument()
89+
})
7890
})

src/pure.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import { tick } from 'svelte'
44
const containerCache = new Map()
55
const componentCache = new Set()
66

7-
const svleteComponentOptions = ['anchor', 'props', 'hydrate', 'intro']
7+
const svelteComponentOptions = [
8+
'anchor',
9+
'props',
10+
'hydrate',
11+
'intro',
12+
'context'
13+
]
814

915
const render = (
1016
Component,
@@ -17,19 +23,21 @@ const render = (
1723
const ComponentConstructor = Component.default || Component
1824

1925
const checkProps = (options) => {
20-
const isProps = !Object.keys(options).some(option => svleteComponentOptions.includes(option))
26+
const isProps = !Object.keys(options).some((option) =>
27+
svelteComponentOptions.includes(option)
28+
)
2129

2230
// Check if any props and Svelte options were accidentally mixed.
2331
if (!isProps) {
24-
const unrecognizedOptions = Object
25-
.keys(options)
26-
.filter(option => !svleteComponentOptions.includes(option))
32+
const unrecognizedOptions = Object.keys(options).filter(
33+
(option) => !svelteComponentOptions.includes(option)
34+
)
2735

2836
if (unrecognizedOptions.length > 0) {
2937
throw Error(`
30-
Unknown options were found [${unrecognizedOptions}]. This might happen if you've mixed
31-
passing in props with Svelte options into the render function. Valid Svelte options
32-
are [${svleteComponentOptions}]. You can either change the prop names, or pass in your
38+
Unknown options were found [${unrecognizedOptions}]. This might happen if you've mixed
39+
passing in props with Svelte options into the render function. Valid Svelte options
40+
are [${svelteComponentOptions}]. You can either change the prop names, or pass in your
3341
props for that component via the \`props\` option.\n\n
3442
Eg: const { /** Results **/ } = render(MyComponent, { props: { /** props here **/ } })\n\n
3543
`)
@@ -76,7 +84,7 @@ const render = (
7684
}
7785
}
7886

79-
const cleanupAtContainer = container => {
87+
const cleanupAtContainer = (container) => {
8088
const { target, component } = containerCache.get(container)
8189

8290
if (componentCache.has(component)) component.$destroy()
@@ -112,6 +120,8 @@ Object.keys(dtlFireEvent).forEach((key) => {
112120
}
113121
})
114122

123+
/* eslint-disable import/export */
124+
115125
export * from '@testing-library/dom'
116126

117127
export {

0 commit comments

Comments
 (0)