Skip to content

Commit fe0d0fa

Browse files
author
Ryan Carniato
authored
Merge pull request #1 from amoutonbrady/main
Cleanups, better build pipeline and publish as common js
2 parents 210086f + a030d2a commit fe0d0fa

14 files changed

Lines changed: 11736 additions & 915 deletions

package-lock.json

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

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"scripts": {
3636
"prepublishOnly": "npm run build",
3737
"clean": "rimraf dist",
38-
"build": "tsc",
38+
"build": "tsc --project tsconfig.build.json",
3939
"test": "jest tests",
4040
"test:watch": "npm test --watch",
4141
"test:coverage": "npm test -- --coverage",
@@ -51,15 +51,16 @@
5151
"@babel/core": "^7.12.16",
5252
"@babel/preset-env": "^7.12.16",
5353
"@babel/preset-typescript": "7.12.16",
54-
"@testing-library/jest-dom": "^5.10.1",
55-
"@types/jest": "^26.0.0",
54+
"@testing-library/jest-dom": "^5.11.9",
55+
"@types/jest": "^26.0.20",
5656
"babel-jest": "^26.6.3",
5757
"babel-preset-solid": "^0.24.2",
5858
"coveralls": "^3.1.0",
59-
"jest": "^26.0.1",
59+
"jest": "^26.6.3",
60+
"prettier": "^2.2.1",
61+
"pretty-format": "^26.6.2",
62+
"rimraf": "^3.0.2",
6063
"solid-js": "^0.24.7",
61-
"prettier": "^2.0.5",
62-
"rimraf": "^3.0.0",
6364
"typescript": "^4.1.5"
6465
},
6566
"peerDependencies": {

src/__tests__/auto-cleanup.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { render } from '..'
1+
import { render } from "..";
22

33
// This just verifies that by importing STL in an
44
// environment which supports afterEach (like jest)
55
// we'll get automatic cleanup between tests.
6-
test('first', () => {
7-
render(() => <div>hi</div>)
8-
})
6+
test("first", () => {
7+
render(() => <div>hi</div>);
8+
});
99

10-
test('second', () => {
11-
expect(document.body.innerHTML).toEqual('')
12-
})
10+
test("second", () => {
11+
expect(document.body.innerHTML).toEqual("");
12+
});

src/__tests__/basic.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import "@testing-library/jest-dom/extend-expect";
22
import { createSignal, createEffect } from "solid-js";
33
import { fireEvent, render } from "..";
44

5-
(globalThis as any)._$HYDRATION = {};
5+
declare global {
6+
var _$HYDRATION: Record<string, any>;
7+
}
8+
9+
globalThis._$HYDRATION = {};
610

711
test("render calls createEffect immediately", () => {
812
const cb = jest.fn();

src/__tests__/cleanup.tsx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
import '@testing-library/jest-dom/extend-expect'
2-
import { onCleanup } from 'solid-js'
3-
import { cleanup, render } from '..'
1+
import "@testing-library/jest-dom/extend-expect";
2+
import { onCleanup } from "solid-js";
3+
import { cleanup, render } from "..";
44

5-
test('cleans up the document', () => {
6-
const spy = jest.fn()
7-
const divId = 'my-div'
5+
test("cleans up the document", () => {
6+
const spy = jest.fn();
7+
const divId = "my-div";
88

99
function Test() {
1010
onCleanup(() => {
11-
expect(document.getElementById(divId)).toBeInTheDocument()
12-
spy()
13-
})
14-
return (<div id={divId} />)
11+
expect(document.getElementById(divId)).toBeInTheDocument();
12+
spy();
13+
});
14+
return <div id={divId} />;
1515
}
1616

17-
render(() => <Test />)
18-
cleanup()
19-
expect(document.body.innerHTML).toBe('')
20-
expect(spy).toHaveBeenCalledTimes(1)
21-
})
17+
render(() => <Test />);
18+
cleanup();
19+
expect(document.body.innerHTML).toBe("");
20+
expect(spy).toHaveBeenCalledTimes(1);
21+
});
2222

23-
test('cleanup does not error when an element is not a child', () => {
24-
render(() => <div />, { container: document.createElement('div') })
25-
cleanup()
26-
})
23+
test("cleanup does not error when an element is not a child", () => {
24+
render(() => <div />, { container: document.createElement("div") });
25+
cleanup();
26+
});

src/__tests__/debug.tsx

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,51 @@
1-
import '@testing-library/jest-dom/extend-expect'
2-
import { screen, render } from '..'
1+
import "@testing-library/jest-dom/extend-expect";
2+
import { screen, render } from "..";
33

44
beforeEach(() => {
5-
jest.spyOn(console, 'log').mockImplementation(() => {})
6-
})
5+
jest.spyOn(console, "log").mockImplementation(() => {});
6+
});
77

88
afterEach(() => {
99
// @ts-ignore
10-
console.log.mockRestore()
11-
})
10+
console.log.mockRestore();
11+
});
1212

13-
test('debug pretty prints the container', () => {
14-
const HelloWorld = () => (<h1>Hello World</h1>)
13+
test("debug pretty prints the container", () => {
14+
const HelloWorld = () => <h1>Hello World</h1>;
1515

16-
const { debug } = render(() => <HelloWorld />)
16+
const { debug } = render(() => <HelloWorld />);
1717

18-
debug()
18+
debug();
1919

20-
expect(console.log).toHaveBeenCalledTimes(1)
21-
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('Hello World'))
22-
})
20+
expect(console.log).toHaveBeenCalledTimes(1);
21+
expect(console.log).toHaveBeenCalledWith(expect.stringContaining("Hello World"));
22+
});
2323

24-
test('debug pretty prints multiple containers', () => {
24+
test("debug pretty prints multiple containers", () => {
2525
const HelloWorld = () => (
2626
<>
2727
<h1 data-testid="testId">Hello World</h1>
2828
<h1 data-testid="testId">Hello World</h1>
2929
</>
30-
)
31-
32-
const { debug } = render(() => <HelloWorld />)
33-
const multipleElements = screen.getAllByTestId('testId')
34-
debug(multipleElements)
35-
expect(console.log).toHaveBeenCalledTimes(2)
36-
expect(console.log).toHaveBeenCalledWith(
37-
expect.stringContaining('Hello World')
38-
)
39-
})
40-
41-
test('allows same arguments as prettyDOM', () => {
42-
const HelloWorld = () => <h1>Hello World</h1>
43-
const { debug, container } = render(() => <HelloWorld />)
44-
debug(container, 6, { highlight: false })
45-
expect(console.log).toHaveBeenCalledTimes(1)
30+
);
31+
32+
const { debug } = render(() => <HelloWorld />);
33+
const multipleElements = screen.getAllByTestId("testId");
34+
debug(multipleElements);
35+
expect(console.log).toHaveBeenCalledTimes(2);
36+
expect(console.log).toHaveBeenCalledWith(expect.stringContaining("Hello World"));
37+
});
38+
39+
test("allows same arguments as prettyDOM", () => {
40+
const HelloWorld = () => <h1>Hello World</h1>;
41+
const { debug, container } = render(() => <HelloWorld />);
42+
debug(container, 6, { highlight: false });
43+
expect(console.log).toHaveBeenCalledTimes(1);
4644
// @ts-ignore
4745
expect(console.log.mock.calls[0]).toMatchInlineSnapshot(`
4846
Array [
4947
"<div>
5048
...",
5149
]
52-
`)
53-
})
50+
`);
51+
});

src/__tests__/end-to-end.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ const fetchAMessage = () =>
1414
});
1515

1616
function ComponentWithLoader() {
17-
const [data] = createResource<{ returnedMessage: string }, string>("data", fetchAMessage);
17+
const [data] = createResource("data", fetchAMessage);
1818
return (
1919
<Show when={!data.loading} fallback={<div>Loading...</div>}>
20-
<div data-testid="message">Loaded this message: {data().returnedMessage}!</div>
20+
<div data-testid="message">Loaded this message: {data()!.returnedMessage}!</div>
2121
</Show>
2222
);
2323
}

src/__tests__/events.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ eventTypes.forEach(({ type, events, elementType, init }) => {
139139

140140
render(() => <Dynamic component={elementType} ref={ref} on={{ [eventProp]: spy }} />);
141141

142+
// @ts-ignore
142143
fireEvent[eventName](ref, init);
143144

144145
expect(spy).toHaveBeenCalledTimes(1);
@@ -154,7 +155,7 @@ test("onInput works", () => {
154155
container: { firstChild: input }
155156
} = render(() => <input type="text" onInput={handler} />);
156157

157-
fireEvent.input(input, { target: { value: "a" } });
158+
fireEvent.input(input!, { target: { value: "a" } });
158159

159160
expect(handler).toHaveBeenCalledTimes(1);
160161
});
@@ -167,7 +168,7 @@ test("calling `fireEvent` directly works too", () => {
167168
} = render(() => <button onClick={handleEvent} />);
168169

169170
fireEvent(
170-
button,
171+
button!,
171172
new Event("MouseEvent", {
172173
bubbles: true,
173174
cancelable: true,

src/__tests__/multi-base.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { render } from "..";
22

33
// These are created once per test suite and reused for each case
4-
let treeA;
5-
let treeB;
4+
let treeA: HTMLDivElement;
5+
let treeB: HTMLDivElement;
66

77
beforeAll(() => {
88
treeA = document.createElement("div");
@@ -12,8 +12,8 @@ beforeAll(() => {
1212
});
1313

1414
afterAll(() => {
15-
treeA.parentNode.removeChild(treeA);
16-
treeB.parentNode.removeChild(treeB);
15+
treeA.parentNode!.removeChild(treeA);
16+
treeB.parentNode!.removeChild(treeB);
1717
});
1818

1919
test("baseElement isolates trees from one another", () => {

src/__tests__/stopwatch.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function StopWatch() {
3333
);
3434
}
3535

36-
const wait = time => new Promise(resolve => setTimeout(resolve, time));
36+
const wait = (time: number) => new Promise(resolve => setTimeout(resolve, time));
3737

3838
test("unmounts a component", async () => {
3939
jest.spyOn(console, "error").mockImplementation(() => {});
@@ -51,5 +51,5 @@ test("unmounts a component", async () => {
5151

5252
// Just wait to see if the interval is cleared or not.
5353
// If it's not, then we'll call setState on an unmounted component and get an error.
54-
await wait(() => expect(console.error).not.toHaveBeenCalled());
54+
await wait((() => expect(console.error).not.toHaveBeenCalled()) as any);
5555
});

0 commit comments

Comments
 (0)