Skip to content

Commit 11de028

Browse files
refactor: upgrade to Jest 29 for fetch support (#654)
* chore(tests): Upgrade to jest@29 * fix file list snap, snack content lint
1 parent 7f676fd commit 11de028

File tree

31 files changed

+1429
-2897
lines changed

31 files changed

+1429
-2897
lines changed

packages/snack-content/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@
3333
"semver": "^7.3.4"
3434
},
3535
"devDependencies": {
36-
"@types/jest": "^27.4.0",
36+
"@types/jest": "^29.5.12",
3737
"@types/semver": "^7.3.9",
3838
"eslint": "^8.49.0",
3939
"eslint-config-universe": "^12.0.0",
40-
"jest": "^27.5.1",
40+
"jest": "^29.7.0",
4141
"jest-prettier": "npm:prettier@^2.8.8",
4242
"prettier": "^3.0.3",
4343
"rimraf": "^3.0.2",
44-
"ts-jest": "~27.1.3",
44+
"ts-jest": "^29.1.2",
4545
"typescript": "^4.1.2"
4646
},
4747
"eslintConfig": {

packages/snack-content/src/__tests__/urls-test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe(parseRuntimeUrl, () => {
4141
it('returns info with only "sdkVersion"', () => {
4242
expect(parseRuntimeUrl('exp://u.expo.dev/xxx?runtime-version=exposdk:69.0.0'))
4343
.toMatchInlineSnapshot(`
44-
Object {
44+
{
4545
"channel": undefined,
4646
"sdkVersion": "69.0.0",
4747
"snack": undefined,
@@ -52,7 +52,7 @@ describe(parseRuntimeUrl, () => {
5252
it('returns info with "sdkVersion" and "snack"', () => {
5353
expect(parseRuntimeUrl('exp://u.expo.dev/xxx?runtime-version=exposdk:69.0.0&snack=snackid'))
5454
.toMatchInlineSnapshot(`
55-
Object {
55+
{
5656
"channel": undefined,
5757
"sdkVersion": "69.0.0",
5858
"snack": "snackid",
@@ -66,7 +66,7 @@ describe(parseRuntimeUrl, () => {
6666
'exp://u.expo.dev/xxx?runtime-version=exposdk:69.0.0&snack-channel=channelid',
6767
),
6868
).toMatchInlineSnapshot(`
69-
Object {
69+
{
7070
"channel": "channelid",
7171
"sdkVersion": "69.0.0",
7272
"snack": undefined,
@@ -80,7 +80,7 @@ describe(parseRuntimeUrl, () => {
8080
'exp://u.expo.dev/xxx?runtime-version=exposdk:69.0.0&snack=snackid&snack-channel=channelid',
8181
),
8282
).toMatchInlineSnapshot(`
83-
Object {
83+
{
8484
"channel": "channelid",
8585
"sdkVersion": "69.0.0",
8686
"snack": "snackid",

packages/snack-eslint-standalone/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@
3434
"@babel/preset-env": "^7.18.9",
3535
"@babel/preset-typescript": "^7.18.6",
3636
"@tsconfig/node16": "^1.0.3",
37-
"@types/jest": "^28.1.6",
38-
"babel-jest": "^28.1.3",
37+
"@types/jest": "^29.5.12",
38+
"babel-jest": "^29.7.0",
3939
"babel-loader": "^8.2.5",
4040
"eslint": "^8.20.0",
4141
"eslint-plugin-react": "^7.30.1",
4242
"eslint-plugin-react-hooks": "^4.6.0",
4343
"eslint-plugin-react-native": "^4.0.0",
44-
"jest": "^28.1.3",
44+
"jest": "^29.7.0",
4545
"node-polyfill-webpack-plugin": "^2.0.0",
4646
"patch-package": "^6.4.7",
4747
"snack-babel-standalone": "^3.0.1",

packages/snack-eslint-standalone/yarn.lock

Lines changed: 718 additions & 453 deletions
Large diffs are not rendered by default.

packages/snack-require-context/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@
5151
"@babel/core": "^7.18.9",
5252
"@babel/types": "^7.12.7",
5353
"@tsconfig/node16": "^1.0.2",
54-
"@types/jest": "^26.0.20",
54+
"@types/jest": "^29.5.12",
5555
"eslint": "^8.49.0",
5656
"eslint-config-universe": "^12.0.0",
57-
"jest": "^26.6.3",
57+
"jest": "^29.7.0",
5858
"prettier": "^3.0.3",
59-
"ts-jest": "^26.5.0",
59+
"ts-jest": "^29.1.2",
6060
"typescript": "^4.7.4"
6161
},
6262
"eslintConfig": {

packages/snack-require-context/src/utils/__tests__/babel.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,37 @@ import { snackRequireContextVirtualModuleBabelPlugin } from '../babel';
55
describe(snackRequireContextVirtualModuleBabelPlugin, () => {
66
it(`creates virtual module for require.context('./app')`, () => {
77
expect(transpile(`require.context('./app')`)).toMatchInlineSnapshot(
8-
`"require(\\"./app?ctx=eyJyIjp0cnVlLCJtIjoiLioiLCJvIjoic3luYyJ9\\");"`,
8+
`"require("./app?ctx=eyJyIjp0cnVlLCJtIjoiLioiLCJvIjoic3luYyJ9");"`,
99
);
1010
});
1111

1212
it(`creates virtual module for require.context('module://components')`, () => {
1313
expect(transpile(`require.context('module://components')`)).toMatchInlineSnapshot(
14-
`"require(\\"module://components?ctx=eyJyIjp0cnVlLCJtIjoiLioiLCJvIjoic3luYyJ9\\");"`,
14+
`"require("module://components?ctx=eyJyIjp0cnVlLCJtIjoiLioiLCJvIjoic3luYyJ9");"`,
1515
);
1616
});
1717

1818
it('creates virtual module for require.context("./app", false)', () => {
1919
expect(transpile(`require.context('./app', false)`)).toMatchInlineSnapshot(
20-
`"require(\\"./app?ctx=eyJyIjpmYWxzZSwibSI6Ii4qIiwibyI6InN5bmMifQ\\");"`,
20+
`"require("./app?ctx=eyJyIjpmYWxzZSwibSI6Ii4qIiwibyI6InN5bmMifQ");"`,
2121
);
2222
});
2323

2424
it('creates virtual module for require.context("./app", false, /\\.mdx$/)', () => {
2525
expect(transpile(`require.context('./app', false, /\\.mdx$/)`)).toMatchInlineSnapshot(
26-
`"require(\\"./app?ctx=eyJyIjpmYWxzZSwibSI6IlxcLm1keCQiLCJvIjoic3luYyJ9\\");"`,
26+
`"require("./app?ctx=eyJyIjpmYWxzZSwibSI6IlxcLm1keCQiLCJvIjoic3luYyJ9");"`,
2727
);
2828
});
2929

3030
it('creates virtual module for require.context("./app", false, /\\.mdx$/, "async")', () => {
3131
expect(transpile(`require.context('./app', false, /\\.mdx$/, 'async')`)).toMatchInlineSnapshot(
32-
`"require(\\"./app?ctx=eyJyIjpmYWxzZSwibSI6IlxcLm1keCQiLCJvIjoiYXN5bmMifQ\\");"`,
32+
`"require("./app?ctx=eyJyIjpmYWxzZSwibSI6IlxcLm1keCQiLCJvIjoiYXN5bmMifQ");"`,
3333
);
3434
});
3535

3636
it('creates virtual module for require.context(EXPO_ROUTER_APP_ROOT)', () => {
3737
expect(transpile(`require.context(process.env.EXPO_ROUTER_APP_ROOT)`)).toMatchInlineSnapshot(
38-
`"require(\\"module://app?ctx=eyJyIjp0cnVlLCJtIjoiLioiLCJvIjoic3luYyJ9\\");"`,
38+
`"require("module://app?ctx=eyJyIjp0cnVlLCJtIjoiLioiLCJvIjoic3luYyJ9");"`,
3939
);
4040
});
4141

@@ -50,7 +50,7 @@ describe(snackRequireContextVirtualModuleBabelPlugin, () => {
5050
`;
5151

5252
expect(transpile(code, { EXPO_ROUTER_IMPORT_MODE: 'async' })).toMatchInlineSnapshot(
53-
`"require(\\"module://app?ctx=eyJyIjp0cnVlLCJtIjoiLioiLCJvIjoiYXN5bmMifQ\\");"`,
53+
`"require("module://app?ctx=eyJyIjp0cnVlLCJtIjoiLioiLCJvIjoiYXN5bmMifQ");"`,
5454
);
5555
});
5656

packages/snack-require-context/src/utils/babel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function snackRequireContextVirtualModuleBabelPlugin({
4848
// Resolve the context directory, either from user code or library code
4949
const contextDirectory =
5050
// @ts-expect-error The plugin options aren't typed
51-
state.opts.directoryResolution === 'relative'
51+
state.opts.directoryResolution === 'relative' && state.filename
5252
? resolveContextDirectory(sanitizeFilePath(state.filename), directory)
5353
: directory;
5454

packages/snack-sdk/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"@expo/spawn-async": "^1.5.0",
4040
"@koa/router": "^10.0.0",
4141
"@types/diff": "^4.0.2",
42-
"@types/jest": "^26.0.20",
42+
"@types/jest": "^29.5.12",
4343
"@types/koa": "^2.11.6",
4444
"@types/koa-bodyparser": "^4.3.0",
4545
"@types/koa__router": "^8.0.3",
@@ -53,12 +53,12 @@
5353
"eslint": "^8.49.0",
5454
"eslint-config-universe": "^12.0.0",
5555
"form-data": "^3.0.0",
56-
"jest": "^26.6.3",
56+
"jest": "^29.7.0",
5757
"jest-fetch-mock": "^3.0.3",
5858
"koa": "^2.13.0",
5959
"koa-bodyparser": "^4.3.0",
6060
"prettier": "^3.0.3",
61-
"ts-jest": "^26.5.0",
61+
"ts-jest": "^29.1.2",
6262
"typedoc": "^0.19.2",
6363
"typedoc-plugin-markdown": "^3.0.11",
6464
"typescript": "^4.1.2"

packages/snack-sdk/src/DependencyResolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export default class DependencyResolver {
9797
data,
9898
);
9999
return;
100-
} catch (e) {
100+
} catch (e: any) {
101101
return Promise.reject(e);
102102
}
103103
}
@@ -106,7 +106,7 @@ export default class DependencyResolver {
106106
throw new Error(error);
107107
}
108108
}
109-
} catch (e) {
109+
} catch (e: any) {
110110
const error = createError({
111111
message: `Failed to resolve dependency '${key}' (${e.message})`,
112112
fileName: key,

packages/snack-sdk/src/FileUploader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ export default class FileUploader {
116116
delete this.status[path];
117117
try {
118118
this.callback({ path, file }, resultURL);
119-
} catch (e) {
119+
} catch (e: any) {
120120
return Promise.reject(e);
121121
}
122122
}
123-
} catch (e) {
123+
} catch (e: any) {
124124
const error = createError({
125125
message: `Failed to upload file ${path} (${e.message})`,
126126
fileName: path,

0 commit comments

Comments
 (0)