Skip to content

Commit d922b4b

Browse files
authored
Merge branch 'main' into add-node-engine-versions-to-ci
2 parents 17eddd6 + af462d0 commit d922b4b

File tree

10 files changed

+94
-33
lines changed

10 files changed

+94
-33
lines changed

.all-contributorsrc

+21-1
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,25 @@
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+
]
124+
},
125+
{
126+
"login": "jgbowser",
127+
"name": "John Bowser",
128+
"avatar_url": "https://avatars.githubusercontent.com/u/66637570?v=4",
129+
"profile": "https://johnbowser.dev/",
130+
"contributions": [
131+
"code",
132+
"test"
133+
]
114134
}
115135
],
116136
"contributorsPerLine": 7,

.github/workflows/release.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- name: 🛑 Cancel Previous Runs
19-
uses: styfle/[email protected].0
19+
uses: styfle/[email protected].1
2020

2121
- name: ⬇️ Checkout repo
22-
uses: actions/checkout@v2
22+
uses: actions/checkout@v3
2323

2424
- name: ⎔ Setup node
25-
uses: actions/setup-node@v2
25+
uses: actions/setup-node@v3
2626
with:
2727
node-version: ${{ matrix.node }}
2828

@@ -35,7 +35,7 @@ jobs:
3535
run: npm run validate
3636

3737
- name: ⬆️ Upload coverage report
38-
uses: codecov/codecov-action@v1
38+
uses: codecov/codecov-action@v2
3939

4040
release:
4141
needs: main
@@ -46,15 +46,15 @@ jobs:
4646
github.ref) && github.event_name == 'push' }}
4747
steps:
4848
- name: 🛑 Cancel Previous Runs
49-
uses: styfle/[email protected].0
49+
uses: styfle/[email protected].1
5050

5151
- name: ⬇️ Checkout repo
52-
uses: actions/checkout@v2
52+
uses: actions/checkout@v3
5353

5454
- name: ⎔ Setup node
55-
uses: actions/setup-node@v2
55+
uses: actions/setup-node@v3
5656
with:
57-
node-version: 14
57+
node-version: 16
5858

5959
- name: 📥 Download deps
6060
uses: bahmutov/npm-install@v1

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,11 @@ 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>
137+
<td align="center"><a href="https://johnbowser.dev/"><img src="https://avatars.githubusercontent.com/u/66637570?v=4?s=100" width="100px;" alt=""/><br /><sub><b>John Bowser</b></sub></a><br /><a href="https://github.com/testing-library/svelte-testing-library/commits?author=jgbowser" title="Code">💻</a> <a href="https://github.com/testing-library/svelte-testing-library/commits?author=jgbowser" title="Tests">⚠️</a></td>
136138
</tr>
137139
</table>
138140

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,31 @@
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",
6464
"@types/jest": "^27.0.0",
6565
"all-contributors-cli": "^6.9.0",
6666
"babel-eslint": "^10.0.3",
67-
"babel-jest": "^27.0.0",
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",
76+
"husky": "^7.0.1",
7777
"jest": "^27.0.0",
78-
"lint-staged": "^10.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",
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

+4
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

+6
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__/render.test.js

+13-1
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/__tests__/rerender.test.js

+9
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,13 @@ describe('rerender', () => {
1919
rerender({ props: { name: '' } })
2020
expect(isDestroyed).toBeTruthy()
2121
})
22+
23+
test('destroys old components on multiple rerenders', () => {
24+
const { rerender, queryByText } = render(Comp, { props: { name: 'Neil' } })
25+
26+
rerender({ props: { name: 'Alex' } })
27+
expect(queryByText('Hello Neil!')).not.toBeInTheDocument()
28+
rerender({ props: { name: 'Geddy' } })
29+
expect(queryByText('Hello Alex!')).not.toBeInTheDocument()
30+
})
2231
})

src/pure.js

+22-14
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
`)
@@ -41,7 +49,7 @@ const render = (
4149
return { props: options }
4250
}
4351

44-
const component = new ComponentConstructor({
52+
let component = new ComponentConstructor({
4553
target,
4654
...checkProps(options)
4755
})
@@ -59,15 +67,15 @@ const render = (
5967
if (componentCache.has(component)) component.$destroy()
6068

6169
// eslint-disable-next-line no-new
62-
const newComponent = new ComponentConstructor({
70+
component = new ComponentConstructor({
6371
target,
6472
...checkProps(options)
6573
})
6674

67-
containerCache.set(container, { target, newComponent })
68-
componentCache.add(newComponent)
75+
containerCache.set(container, { target, component })
76+
componentCache.add(component)
6977

70-
newComponent.$$.on_destroy.push(() => { componentCache.delete(newComponent) })
78+
component.$$.on_destroy.push(() => { componentCache.delete(component) })
7179
},
7280
unmount: () => {
7381
if (componentCache.has(component)) component.$destroy()
@@ -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()

0 commit comments

Comments
 (0)