@cedarjs/testing 0.1.1 → 0.1.2-next.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/jest/api/jest.setup.js +1 -1
- package/config/jest/babelPlugins/__tests__/__fixtures__/cell/cell-with-commented-exports/code.js +28 -0
- package/config/jest/babelPlugins/__tests__/__fixtures__/cell/cell-with-commented-exports/output.js +35 -0
- package/config/jest/babelPlugins/__tests__/__fixtures__/cell/cell-with-default-and-other-named-export/code.js +7 -0
- package/config/jest/babelPlugins/__tests__/__fixtures__/cell/cell-with-default-and-other-named-export/output.js +6 -0
- package/config/jest/babelPlugins/__tests__/__fixtures__/cell/cell-with-default-export/code.js +3 -0
- package/config/jest/babelPlugins/__tests__/__fixtures__/cell/cell-with-default-export/output.js +3 -0
- package/config/jest/babelPlugins/__tests__/__fixtures__/cell/cell-with-required-exports/code.js +28 -0
- package/config/jest/babelPlugins/__tests__/__fixtures__/cell/cell-with-required-exports/output.js +34 -0
- package/config/jest/babelPlugins/__tests__/__fixtures__/viteDistDir/client-build-manifest.json +59 -0
- package/config/jest/babelPlugins/__tests__/babel-plugin-redwood-cell.test.ts +11 -0
- package/config/jest/babelPlugins/babel-plugin-redwood-cell.js +142 -0
- package/config/jest/package.json +3 -0
- package/config/jest/web/jest-preset.js +2 -2
- package/config/jest/web/jest.setup.js +2 -2
- package/config/jest/web/webBabelConfig.js +16 -1
- package/dist/api/apiFunction.js +4 -30
- package/dist/api/directUrlHelpers.js +4 -39
- package/dist/api/directive.js +13 -38
- package/dist/api/index.d.ts +3 -3
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +3 -26
- package/dist/api/scenario.js +2 -26
- package/dist/cache/index.js +2 -26
- package/dist/cjs/api/apiFunction.d.ts +37 -0
- package/dist/cjs/api/apiFunction.d.ts.map +1 -0
- package/dist/cjs/api/apiFunction.js +89 -0
- package/dist/cjs/api/directUrlHelpers.d.ts +3 -0
- package/dist/cjs/api/directUrlHelpers.d.ts.map +1 -0
- package/dist/cjs/api/directUrlHelpers.js +60 -0
- package/dist/cjs/api/directive.d.ts +51 -0
- package/dist/cjs/api/directive.d.ts.map +1 -0
- package/dist/cjs/api/directive.js +77 -0
- package/dist/cjs/api/index.d.ts +4 -0
- package/dist/cjs/api/index.d.ts.map +1 -0
- package/dist/cjs/api/index.js +26 -0
- package/dist/cjs/api/scenario.d.ts +108 -0
- package/dist/cjs/api/scenario.d.ts.map +1 -0
- package/dist/cjs/api/scenario.js +30 -0
- package/dist/cjs/cache/index.d.ts +50 -0
- package/dist/cjs/cache/index.d.ts.map +1 -0
- package/dist/cjs/cache/index.js +104 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/web/MockParamsProvider.d.ts +7 -0
- package/dist/cjs/web/MockParamsProvider.d.ts.map +1 -0
- package/dist/cjs/web/MockParamsProvider.js +44 -0
- package/dist/cjs/web/MockProviders.d.ts +9 -0
- package/dist/cjs/web/MockProviders.d.ts.map +1 -0
- package/dist/cjs/web/MockProviders.js +53 -0
- package/dist/cjs/web/MockRouter.d.ts +14 -0
- package/dist/cjs/web/MockRouter.d.ts.map +1 -0
- package/dist/cjs/web/MockRouter.js +48 -0
- package/dist/cjs/web/customRender.d.ts +6 -0
- package/dist/cjs/web/customRender.d.ts.map +1 -0
- package/dist/cjs/web/customRender.js +54 -0
- package/dist/cjs/web/fileMock.d.ts +9 -0
- package/dist/cjs/web/fileMock.d.ts.map +1 -0
- package/dist/cjs/web/fileMock.js +24 -0
- package/dist/cjs/web/findCellMocks.d.ts +2 -0
- package/dist/cjs/web/findCellMocks.d.ts.map +1 -0
- package/dist/cjs/web/findCellMocks.js +45 -0
- package/dist/cjs/web/global.d.ts +6 -0
- package/dist/cjs/web/global.d.ts.map +1 -0
- package/dist/cjs/web/global.js +1 -0
- package/dist/cjs/web/index.d.ts +6 -0
- package/dist/cjs/web/index.d.ts.map +1 -0
- package/dist/cjs/web/index.js +41 -0
- package/dist/cjs/web/mockAuth.d.ts +29 -0
- package/dist/cjs/web/mockAuth.d.ts.map +1 -0
- package/dist/cjs/web/mockAuth.js +89 -0
- package/dist/cjs/web/mockRequests.d.ts +30 -0
- package/dist/cjs/web/mockRequests.d.ts.map +1 -0
- package/dist/cjs/web/mockRequests.js +139 -0
- package/dist/web/MockParamsProvider.js +7 -41
- package/dist/web/MockProviders.d.ts.map +1 -1
- package/dist/web/MockProviders.js +10 -44
- package/dist/web/MockRouter.js +10 -37
- package/dist/web/customRender.js +9 -44
- package/dist/web/fileMock.js +3 -23
- package/dist/web/findCellMocks.js +4 -38
- package/dist/web/global.d.ts +1 -1
- package/dist/web/global.d.ts.map +1 -1
- package/dist/web/global.js +0 -1
- package/dist/web/index.d.ts +4 -5
- package/dist/web/index.d.ts.map +1 -1
- package/dist/web/index.js +13 -41
- package/dist/web/mockAuth.js +12 -49
- package/dist/web/mockRequests.js +6 -37
- package/package.json +78 -14
- package/api/index.js +0 -2
- package/api/package.json +0 -4
- package/cache/index.js +0 -2
- package/cache/package.json +0 -4
- package/web/index.js +0 -2
- package/web/package.json +0 -4
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// @NOTE without these imports in the setup file, mockCurrentUser
|
|
5
5
|
// will remain undefined in the user's tests
|
|
6
6
|
// Remember to use specific imports
|
|
7
|
-
const { defineScenario } = require('@cedarjs/testing/dist/api/scenario')
|
|
7
|
+
const { defineScenario } = require('@cedarjs/testing/dist/cjs/api/scenario')
|
|
8
8
|
|
|
9
9
|
// @NOTE we do this because jest.setup.js runs every time in each context
|
|
10
10
|
// while jest-preset runs once. This significantly reduces memory footprint, and testing time
|
package/config/jest/babelPlugins/__tests__/__fixtures__/cell/cell-with-commented-exports/code.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const QUERY = gql`
|
|
2
|
+
query {
|
|
3
|
+
posts {
|
|
4
|
+
id
|
|
5
|
+
title
|
|
6
|
+
body
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
`
|
|
10
|
+
|
|
11
|
+
// export const beforeQuery = () => ({})
|
|
12
|
+
export const afterQuery = () => ({})
|
|
13
|
+
|
|
14
|
+
export function Loading() {
|
|
15
|
+
return 'Loading'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// export function Empty() {
|
|
19
|
+
// return 'Empty'
|
|
20
|
+
// }
|
|
21
|
+
|
|
22
|
+
export function Failure({ error }) {
|
|
23
|
+
return error.message
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const Success = ({ posts }) => {
|
|
27
|
+
return JSON.stringify(posts, null, 2)
|
|
28
|
+
}
|
package/config/jest/babelPlugins/__tests__/__fixtures__/cell/cell-with-commented-exports/output.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createCell } from '@cedarjs/web'
|
|
2
|
+
export const QUERY = gql`
|
|
3
|
+
query {
|
|
4
|
+
posts {
|
|
5
|
+
id
|
|
6
|
+
title
|
|
7
|
+
body
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
`
|
|
11
|
+
|
|
12
|
+
// export const beforeQuery = () => ({})
|
|
13
|
+
export const afterQuery = () => ({})
|
|
14
|
+
export function Loading() {
|
|
15
|
+
return 'Loading'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// export function Empty() {
|
|
19
|
+
// return 'Empty'
|
|
20
|
+
// }
|
|
21
|
+
|
|
22
|
+
export function Failure({ error }) {
|
|
23
|
+
return error.message
|
|
24
|
+
}
|
|
25
|
+
export const Success = ({ posts }) => {
|
|
26
|
+
return JSON.stringify(posts, null, 2)
|
|
27
|
+
}
|
|
28
|
+
export default createCell({
|
|
29
|
+
QUERY,
|
|
30
|
+
afterQuery,
|
|
31
|
+
Loading,
|
|
32
|
+
Failure,
|
|
33
|
+
Success,
|
|
34
|
+
displayName: 'code',
|
|
35
|
+
})
|
package/config/jest/babelPlugins/__tests__/__fixtures__/cell/cell-with-required-exports/code.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const QUERY = gql`
|
|
2
|
+
query {
|
|
3
|
+
posts {
|
|
4
|
+
id
|
|
5
|
+
title
|
|
6
|
+
body
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
`
|
|
10
|
+
|
|
11
|
+
export const beforeQuery = () => ({})
|
|
12
|
+
export const afterQuery = () => ({})
|
|
13
|
+
|
|
14
|
+
export function Loading() {
|
|
15
|
+
return 'Loading'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function Empty() {
|
|
19
|
+
return 'Empty'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function Failure({ error }) {
|
|
23
|
+
return error.message
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const Success = ({ posts }) => {
|
|
27
|
+
return JSON.stringify(posts, null, 2)
|
|
28
|
+
}
|
package/config/jest/babelPlugins/__tests__/__fixtures__/cell/cell-with-required-exports/output.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createCell } from '@cedarjs/web'
|
|
2
|
+
export const QUERY = gql`
|
|
3
|
+
query {
|
|
4
|
+
posts {
|
|
5
|
+
id
|
|
6
|
+
title
|
|
7
|
+
body
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
`
|
|
11
|
+
export const beforeQuery = () => ({})
|
|
12
|
+
export const afterQuery = () => ({})
|
|
13
|
+
export function Loading() {
|
|
14
|
+
return 'Loading'
|
|
15
|
+
}
|
|
16
|
+
export function Empty() {
|
|
17
|
+
return 'Empty'
|
|
18
|
+
}
|
|
19
|
+
export function Failure({ error }) {
|
|
20
|
+
return error.message
|
|
21
|
+
}
|
|
22
|
+
export const Success = ({ posts }) => {
|
|
23
|
+
return JSON.stringify(posts, null, 2)
|
|
24
|
+
}
|
|
25
|
+
export default createCell({
|
|
26
|
+
QUERY,
|
|
27
|
+
beforeQuery,
|
|
28
|
+
afterQuery,
|
|
29
|
+
Loading,
|
|
30
|
+
Empty,
|
|
31
|
+
Failure,
|
|
32
|
+
Success,
|
|
33
|
+
displayName: 'code',
|
|
34
|
+
})
|
package/config/jest/babelPlugins/__tests__/__fixtures__/viteDistDir/client-build-manifest.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"components/Post/Posts/image1.jpg": {
|
|
3
|
+
"file": "assets/image1-hash.jpg",
|
|
4
|
+
"src": "components/Post/Posts/image1.jpg"
|
|
5
|
+
},
|
|
6
|
+
"index.css": {
|
|
7
|
+
"file": "assets/index-3f5e7a04.css",
|
|
8
|
+
"src": "index.css"
|
|
9
|
+
},
|
|
10
|
+
"index.html": {
|
|
11
|
+
"assets": [
|
|
12
|
+
"assets/image1-hash.jpg",
|
|
13
|
+
"assets/image2-hash.jpeg",
|
|
14
|
+
"assets/image3-hash.png",
|
|
15
|
+
"assets/image4-hash.bmp",
|
|
16
|
+
"assets/doc-hash.pdf",
|
|
17
|
+
"assets/funny-hash.gif"
|
|
18
|
+
],
|
|
19
|
+
"css": [
|
|
20
|
+
"assets/index-3f5e7a04.css"
|
|
21
|
+
],
|
|
22
|
+
"dynamicImports": [
|
|
23
|
+
"pages/AboutPage/AboutPage.tsx",
|
|
24
|
+
"pages/BlogPostPage/BlogPostPage.tsx",
|
|
25
|
+
"pages/ContactUsPage/ContactUsPage.tsx",
|
|
26
|
+
"pages/DoublePage/DoublePage.tsx",
|
|
27
|
+
"pages/ForgotPasswordPage/ForgotPasswordPage.tsx",
|
|
28
|
+
"pages/Post/PostPage/PostPage.tsx",
|
|
29
|
+
"pages/Post/PostsPage/PostsPage.tsx"
|
|
30
|
+
],
|
|
31
|
+
"file": "assets/index-abef5d50.js",
|
|
32
|
+
"isEntry": true,
|
|
33
|
+
"src": "index.html"
|
|
34
|
+
},
|
|
35
|
+
"pages/HomePage/image1.jpg": {
|
|
36
|
+
"file": "assets/image1-hash.jpg",
|
|
37
|
+
"src": "components/Post/Posts/image1.jpg"
|
|
38
|
+
},
|
|
39
|
+
"pages/HomePage/image2.jpeg": {
|
|
40
|
+
"file": "assets/image2-hash.jpeg",
|
|
41
|
+
"src": "pages/HomePage/image2.jpeg"
|
|
42
|
+
},
|
|
43
|
+
"pages/HomePage/image3.png": {
|
|
44
|
+
"file": "assets/image3-hash.png",
|
|
45
|
+
"src": "pages/HomePage/image3.png"
|
|
46
|
+
},
|
|
47
|
+
"pages/HomePage/image4.bmp": {
|
|
48
|
+
"file": "assets/image4-hash.bmp",
|
|
49
|
+
"src": "pages/HomePage/image4.bmp"
|
|
50
|
+
},
|
|
51
|
+
"pages/HomePage/funny.gif": {
|
|
52
|
+
"file": "assets/funny-hash.gif",
|
|
53
|
+
"src": "pages/HomePage/funny.gif"
|
|
54
|
+
},
|
|
55
|
+
"pdf/invoice.pdf": {
|
|
56
|
+
"file": "assets/invoice-7d64ed28.pdf",
|
|
57
|
+
"src": "pdf/invoice.pdf"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import path from 'path'
|
|
2
|
+
|
|
3
|
+
import pluginTester from 'babel-plugin-tester'
|
|
4
|
+
|
|
5
|
+
import redwoodCellPlugin from '../babel-plugin-redwood-cell'
|
|
6
|
+
|
|
7
|
+
pluginTester({
|
|
8
|
+
plugin: redwoodCellPlugin,
|
|
9
|
+
pluginName: 'babel-plugin-redwood-cell',
|
|
10
|
+
fixtures: path.join(__dirname, '__fixtures__/cell'),
|
|
11
|
+
})
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
const { parse } = require('path')
|
|
2
|
+
|
|
3
|
+
// This wraps a file that has a suffix of `Cell` in Redwood's `createCell` higher
|
|
4
|
+
// order component. The HOC deals with the lifecycle methods during a GraphQL query.
|
|
5
|
+
//
|
|
6
|
+
// ```js
|
|
7
|
+
// import { createCell } from '@cedarjs/web'
|
|
8
|
+
// <YOUR CODE>
|
|
9
|
+
// export default createCell({ QUERY, Loading, Success, Failure, isEmpty, Empty, beforeQuery, afterQuery, displayName })
|
|
10
|
+
// ```
|
|
11
|
+
//
|
|
12
|
+
// To debug the output of the plugin, you can use the following:
|
|
13
|
+
// ```
|
|
14
|
+
// import generate from '@babel/generator'
|
|
15
|
+
// // ...
|
|
16
|
+
// console.log(generate(path.node).code)
|
|
17
|
+
// ```
|
|
18
|
+
|
|
19
|
+
// A cell can export the declarations below.
|
|
20
|
+
const EXPECTED_EXPORTS_FROM_CELL = [
|
|
21
|
+
'beforeQuery',
|
|
22
|
+
'QUERY',
|
|
23
|
+
'data',
|
|
24
|
+
'isEmpty',
|
|
25
|
+
'afterQuery',
|
|
26
|
+
'Loading',
|
|
27
|
+
'Success',
|
|
28
|
+
'Failure',
|
|
29
|
+
'Empty',
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
module.exports = function ({ types: t }) {
|
|
33
|
+
// This array will collect exports from the Cell file during
|
|
34
|
+
// ExportNamedDeclaration
|
|
35
|
+
// - collected exports will then be passed to `createCell`
|
|
36
|
+
// - The array is reset every time we `enter` a new Program
|
|
37
|
+
let exportNames = []
|
|
38
|
+
let hasDefaultExport = false
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
name: 'babel-plugin-redwood-cell',
|
|
42
|
+
visitor: {
|
|
43
|
+
ExportDefaultDeclaration() {
|
|
44
|
+
hasDefaultExport = true
|
|
45
|
+
},
|
|
46
|
+
ExportNamedDeclaration(path) {
|
|
47
|
+
const declaration = path.node.declaration
|
|
48
|
+
|
|
49
|
+
if (!declaration) {
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let name
|
|
54
|
+
if (declaration.type === 'VariableDeclaration') {
|
|
55
|
+
const id = declaration.declarations[0].id
|
|
56
|
+
name = id.name
|
|
57
|
+
}
|
|
58
|
+
if (declaration.type === 'FunctionDeclaration') {
|
|
59
|
+
name = declaration?.id?.name
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (name && EXPECTED_EXPORTS_FROM_CELL.includes(name)) {
|
|
63
|
+
exportNames.push(name)
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
Program: {
|
|
67
|
+
enter() {
|
|
68
|
+
// Reset variables as they're still in scope from the previous file
|
|
69
|
+
// babel transformed in the same process
|
|
70
|
+
exportNames = []
|
|
71
|
+
hasDefaultExport = false
|
|
72
|
+
},
|
|
73
|
+
exit(path) {
|
|
74
|
+
const hasQueryOrDataExport =
|
|
75
|
+
exportNames.includes('QUERY') || exportNames.includes('data')
|
|
76
|
+
|
|
77
|
+
// If the file already has a default export then
|
|
78
|
+
// 1. It's likely not a cell, or it's a cell that's already been
|
|
79
|
+
// wrapped in `createCell`
|
|
80
|
+
// 2. If we added another default export we'd be breaking JS module
|
|
81
|
+
// rules. There can only be one default export.
|
|
82
|
+
// If there's no `QUERY` or `data` export it's not a valid cell
|
|
83
|
+
if (hasDefaultExport || !hasQueryOrDataExport) {
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// TODO (RSC): When we want to support `data = async () => {}` in
|
|
88
|
+
// client cells as well, we'll need a different heuristic here
|
|
89
|
+
// If we want to support `QUERY` (gql) cells on the server we'll
|
|
90
|
+
// also need a different heuristic
|
|
91
|
+
const createCellHookName = exportNames.includes('data')
|
|
92
|
+
? 'createServerCell'
|
|
93
|
+
: 'createCell'
|
|
94
|
+
const importFrom = exportNames.includes('data')
|
|
95
|
+
? '@cedarjs/web/dist/components/cell/createServerCell'
|
|
96
|
+
: '@cedarjs/web'
|
|
97
|
+
|
|
98
|
+
// Insert at the top of the file:
|
|
99
|
+
// + import { createCell } from '@cedarjs/web'
|
|
100
|
+
path.node.body.unshift(
|
|
101
|
+
t.importDeclaration(
|
|
102
|
+
[
|
|
103
|
+
t.importSpecifier(
|
|
104
|
+
t.identifier(createCellHookName),
|
|
105
|
+
t.identifier(createCellHookName),
|
|
106
|
+
),
|
|
107
|
+
],
|
|
108
|
+
t.stringLiteral(importFrom),
|
|
109
|
+
),
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
// Insert at the bottom of the file:
|
|
113
|
+
// + export default createCell({ QUERY?, Loading?, Success?, Failure?, Empty?, beforeQuery?, isEmpty, afterQuery?, displayName? })
|
|
114
|
+
path.node.body.push(
|
|
115
|
+
t.exportDefaultDeclaration(
|
|
116
|
+
t.callExpression(t.identifier(createCellHookName), [
|
|
117
|
+
t.objectExpression([
|
|
118
|
+
...exportNames.map((name) =>
|
|
119
|
+
t.objectProperty(
|
|
120
|
+
t.identifier(name),
|
|
121
|
+
t.identifier(name),
|
|
122
|
+
false,
|
|
123
|
+
true,
|
|
124
|
+
),
|
|
125
|
+
),
|
|
126
|
+
// Add the `displayName` property so we can name the Cell
|
|
127
|
+
// after the filename.
|
|
128
|
+
t.objectProperty(
|
|
129
|
+
t.identifier('displayName'),
|
|
130
|
+
t.stringLiteral(parse(this.file.opts.filename).name),
|
|
131
|
+
false,
|
|
132
|
+
true,
|
|
133
|
+
),
|
|
134
|
+
]),
|
|
135
|
+
]),
|
|
136
|
+
),
|
|
137
|
+
)
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -52,7 +52,7 @@ module.exports = {
|
|
|
52
52
|
// We replace imports to "@cedarjs/router" with our own "mock" implementation.
|
|
53
53
|
'^@cedarjs/router$': path.join(
|
|
54
54
|
NODE_MODULES_PATH,
|
|
55
|
-
'@cedarjs/testing/dist/web/MockRouter.js',
|
|
55
|
+
'@cedarjs/testing/dist/cjs/web/MockRouter.js',
|
|
56
56
|
),
|
|
57
57
|
'^@cedarjs/web$': path.join(NODE_MODULES_PATH, '@cedarjs/web/dist/cjs'),
|
|
58
58
|
|
|
@@ -60,7 +60,7 @@ module.exports = {
|
|
|
60
60
|
// clients, which in turn lets us mock `useAuth` in tests
|
|
61
61
|
'^@cedarjs/auth$': path.join(
|
|
62
62
|
NODE_MODULES_PATH,
|
|
63
|
-
'@cedarjs/testing/dist/web/mockAuth.js',
|
|
63
|
+
'@cedarjs/testing/dist/cjs/web/mockAuth.js',
|
|
64
64
|
),
|
|
65
65
|
|
|
66
66
|
// @NOTE: Import @cedarjs/testing in web tests, and it automatically remaps to the web side only
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
require('@testing-library/jest-dom')
|
|
4
4
|
require('whatwg-fetch')
|
|
5
5
|
|
|
6
|
-
const { findCellMocks } = require('@cedarjs/testing/dist/web/findCellMocks')
|
|
6
|
+
const { findCellMocks } = require('@cedarjs/testing/dist/cjs/web/findCellMocks')
|
|
7
7
|
const {
|
|
8
8
|
startMSW,
|
|
9
9
|
setupRequestHandlers,
|
|
@@ -11,7 +11,7 @@ const {
|
|
|
11
11
|
mockGraphQLMutation,
|
|
12
12
|
mockGraphQLQuery,
|
|
13
13
|
mockCurrentUser,
|
|
14
|
-
} = require('@cedarjs/testing/dist/web/mockRequests')
|
|
14
|
+
} = require('@cedarjs/testing/dist/cjs/web/mockRequests')
|
|
15
15
|
|
|
16
16
|
global.mockGraphQLQuery = mockGraphQLQuery
|
|
17
17
|
global.mockGraphQLMutation = mockGraphQLMutation
|
|
@@ -1,3 +1,18 @@
|
|
|
1
1
|
const { getWebSideDefaultBabelConfig } = require('@cedarjs/babel-config')
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const redwoodCellsPlugin = require('../babelPlugins/babel-plugin-redwood-cell')
|
|
4
|
+
|
|
5
|
+
const defaultWebSideBabelConfig = getWebSideDefaultBabelConfig({
|
|
6
|
+
forJest: true,
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
...defaultWebSideBabelConfig,
|
|
11
|
+
overrides: [
|
|
12
|
+
...defaultWebSideBabelConfig.overrides,
|
|
13
|
+
{
|
|
14
|
+
test: /.+Cell.(js|tsx|jsx)$/,
|
|
15
|
+
plugins: [redwoodCellsPlugin],
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
}
|
package/dist/api/apiFunction.js
CHANGED
|
@@ -1,29 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var apiFunction_exports = {};
|
|
20
|
-
__export(apiFunction_exports, {
|
|
21
|
-
mockContext: () => mockContext,
|
|
22
|
-
mockHttpEvent: () => mockHttpEvent,
|
|
23
|
-
mockSignedWebhook: () => mockSignedWebhook
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(apiFunction_exports);
|
|
26
|
-
var import_webhooks = require("@cedarjs/api/webhooks");
|
|
1
|
+
import { signPayload } from "@cedarjs/api/webhooks";
|
|
27
2
|
const mockHttpEvent = ({
|
|
28
3
|
payload = null,
|
|
29
4
|
signature,
|
|
@@ -70,7 +45,7 @@ const mockSignedWebhook = ({
|
|
|
70
45
|
...others
|
|
71
46
|
}) => {
|
|
72
47
|
const payloadAsString = typeof payload === "string" ? payload : JSON.stringify(payload);
|
|
73
|
-
const signature =
|
|
48
|
+
const signature = signPayload(signatureType, {
|
|
74
49
|
payload: payloadAsString,
|
|
75
50
|
secret
|
|
76
51
|
});
|
|
@@ -81,9 +56,8 @@ const mockSignedWebhook = ({
|
|
|
81
56
|
...others
|
|
82
57
|
});
|
|
83
58
|
};
|
|
84
|
-
|
|
85
|
-
0 && (module.exports = {
|
|
59
|
+
export {
|
|
86
60
|
mockContext,
|
|
87
61
|
mockHttpEvent,
|
|
88
62
|
mockSignedWebhook
|
|
89
|
-
}
|
|
63
|
+
};
|
|
@@ -1,40 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var directUrlHelpers_exports = {};
|
|
30
|
-
__export(directUrlHelpers_exports, {
|
|
31
|
-
checkAndReplaceDirectUrl: () => checkAndReplaceDirectUrl,
|
|
32
|
-
getDefaultDb: () => getDefaultDb
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(directUrlHelpers_exports);
|
|
35
|
-
var import_path = __toESM(require("path"));
|
|
1
|
+
import path from "path";
|
|
36
2
|
function getDefaultDb(rwjsCwd) {
|
|
37
|
-
return `file:${
|
|
3
|
+
return `file:${path.join(rwjsCwd, ".redwood", "test.db")}`;
|
|
38
4
|
}
|
|
39
5
|
function checkAndReplaceDirectUrl(prismaSchema, defaultDb) {
|
|
40
6
|
const directUrl = prismaSchema.match(PRISMA_DIRECT_URL_REGEXP);
|
|
@@ -53,8 +19,7 @@ function checkAndReplaceDirectUrl(prismaSchema, defaultDb) {
|
|
|
53
19
|
}
|
|
54
20
|
const PRISMA_DIRECT_URL_REGEXP = /directUrl(\s*)=(\s*)env\(('|")(.*)('|")\)/g;
|
|
55
21
|
const BETWEEN_PARENTHESES_REGEXP = /\(('|")([^)]+)('|")\)/;
|
|
56
|
-
|
|
57
|
-
0 && (module.exports = {
|
|
22
|
+
export {
|
|
58
23
|
checkAndReplaceDirectUrl,
|
|
59
24
|
getDefaultDb
|
|
60
|
-
}
|
|
25
|
+
};
|
package/dist/api/directive.js
CHANGED
|
@@ -1,49 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var directive_exports = {};
|
|
20
|
-
__export(directive_exports, {
|
|
21
|
-
getDirectiveName: () => import_graphql_server2.getDirectiveName,
|
|
22
|
-
mockRedwoodDirective: () => mockRedwoodDirective
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(directive_exports);
|
|
25
|
-
var import_context = require("@cedarjs/context");
|
|
26
|
-
var import_graphql_server = require("@cedarjs/graphql-server");
|
|
27
|
-
var import_graphql_server2 = require("@cedarjs/graphql-server");
|
|
1
|
+
import { setContext, context as globalContext } from "@cedarjs/context";
|
|
2
|
+
import { DirectiveType } from "@cedarjs/graphql-server";
|
|
3
|
+
import { getDirectiveName } from "@cedarjs/graphql-server";
|
|
28
4
|
const mockRedwoodDirective = (directive, executionMock) => {
|
|
29
5
|
const { directiveArgs, context, ...others } = executionMock;
|
|
30
6
|
if (directive.onResolvedValue.constructor.name === "AsyncFunction") {
|
|
31
7
|
return async () => {
|
|
32
8
|
if (context !== void 0) {
|
|
33
|
-
|
|
9
|
+
setContext(context);
|
|
34
10
|
}
|
|
35
|
-
if (directive.type ===
|
|
11
|
+
if (directive.type === DirectiveType.TRANSFORMER) {
|
|
36
12
|
const { mockedResolvedValue } = others;
|
|
37
13
|
return directive.onResolvedValue({
|
|
38
14
|
resolvedValue: mockedResolvedValue,
|
|
39
15
|
directiveArgs: directiveArgs ?? {},
|
|
40
|
-
context:
|
|
16
|
+
context: globalContext,
|
|
41
17
|
...others
|
|
42
18
|
});
|
|
43
19
|
} else {
|
|
44
20
|
await directive.onResolvedValue({
|
|
45
21
|
directiveArgs: directiveArgs ?? {},
|
|
46
|
-
context:
|
|
22
|
+
context: globalContext,
|
|
47
23
|
...others
|
|
48
24
|
});
|
|
49
25
|
}
|
|
@@ -51,27 +27,26 @@ const mockRedwoodDirective = (directive, executionMock) => {
|
|
|
51
27
|
}
|
|
52
28
|
return () => {
|
|
53
29
|
if (context !== void 0) {
|
|
54
|
-
|
|
30
|
+
setContext(context);
|
|
55
31
|
}
|
|
56
|
-
if (directive.type ===
|
|
32
|
+
if (directive.type === DirectiveType.TRANSFORMER) {
|
|
57
33
|
const { mockedResolvedValue } = others;
|
|
58
34
|
return directive.onResolvedValue({
|
|
59
35
|
resolvedValue: mockedResolvedValue,
|
|
60
36
|
directiveArgs: directiveArgs ?? {},
|
|
61
|
-
context:
|
|
37
|
+
context: globalContext,
|
|
62
38
|
...others
|
|
63
39
|
});
|
|
64
40
|
} else {
|
|
65
41
|
directive.onResolvedValue({
|
|
66
42
|
directiveArgs: directiveArgs ?? {},
|
|
67
|
-
context:
|
|
43
|
+
context: globalContext,
|
|
68
44
|
...others
|
|
69
45
|
});
|
|
70
46
|
}
|
|
71
47
|
};
|
|
72
48
|
};
|
|
73
|
-
|
|
74
|
-
0 && (module.exports = {
|
|
49
|
+
export {
|
|
75
50
|
getDirectiveName,
|
|
76
51
|
mockRedwoodDirective
|
|
77
|
-
}
|
|
52
|
+
};
|
package/dist/api/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './apiFunction';
|
|
2
|
-
export * from './scenario';
|
|
3
|
-
export * from './directive';
|
|
1
|
+
export * from './apiFunction.js';
|
|
2
|
+
export * from './scenario.js';
|
|
3
|
+
export * from './directive.js';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/api/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA"}
|