@cedarjs/testing 1.0.0-canary.12316 → 1.0.0-canary.12318

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.
@@ -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
+ }
@@ -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
+ })
@@ -0,0 +1,7 @@
1
+ export const Success = () => {
2
+ return 'string'
3
+ }
4
+
5
+ export default () => {
6
+ return 'string'
7
+ }
@@ -0,0 +1,6 @@
1
+ export const Success = () => {
2
+ return 'string'
3
+ }
4
+ export default () => {
5
+ return 'string'
6
+ }
@@ -0,0 +1,3 @@
1
+ export default () => {
2
+ return 'string'
3
+ }
@@ -0,0 +1,3 @@
1
+ export default () => {
2
+ return 'string'
3
+ }
@@ -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
+ }
@@ -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
+ })
@@ -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
+ }
@@ -1,3 +1,18 @@
1
1
  const { getWebSideDefaultBabelConfig } = require('@cedarjs/babel-config')
2
2
 
3
- module.exports = getWebSideDefaultBabelConfig({ forJest: true })
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/testing",
3
- "version": "1.0.0-canary.12316+9fbbf96b8",
3
+ "version": "1.0.0-canary.12318+74d039296",
4
4
  "description": "Tools, wrappers and configuration for testing a Cedar project.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,13 +28,13 @@
28
28
  "test:watch": "vitest watch"
29
29
  },
30
30
  "dependencies": {
31
- "@cedarjs/auth": "1.0.0-canary.12316",
32
- "@cedarjs/babel-config": "1.0.0-canary.12316",
33
- "@cedarjs/context": "1.0.0-canary.12316",
34
- "@cedarjs/graphql-server": "1.0.0-canary.12316",
35
- "@cedarjs/project-config": "1.0.0-canary.12316",
36
- "@cedarjs/router": "1.0.0-canary.12316",
37
- "@cedarjs/web": "1.0.0-canary.12316",
31
+ "@cedarjs/auth": "1.0.0-canary.12318",
32
+ "@cedarjs/babel-config": "1.0.0-canary.12318",
33
+ "@cedarjs/context": "1.0.0-canary.12318",
34
+ "@cedarjs/graphql-server": "1.0.0-canary.12318",
35
+ "@cedarjs/project-config": "1.0.0-canary.12318",
36
+ "@cedarjs/router": "1.0.0-canary.12318",
37
+ "@cedarjs/web": "1.0.0-canary.12318",
38
38
  "@testing-library/jest-dom": "6.5.0",
39
39
  "@testing-library/react": "14.3.1",
40
40
  "@testing-library/user-event": "14.5.2",
@@ -52,7 +52,7 @@
52
52
  "whatwg-fetch": "3.6.20"
53
53
  },
54
54
  "devDependencies": {
55
- "@cedarjs/framework-tools": "1.0.0-canary.12316",
55
+ "@cedarjs/framework-tools": "1.0.0-canary.12318",
56
56
  "concurrently": "8.2.2",
57
57
  "jsdom": "24.1.3",
58
58
  "publint": "0.3.12",
@@ -60,5 +60,5 @@
60
60
  "typescript": "5.6.2",
61
61
  "vitest": "2.1.9"
62
62
  },
63
- "gitHead": "9fbbf96b848616acb9561c86b887e355c92ef351"
63
+ "gitHead": "74d03929677d47123af04b297d4748e7d125d36e"
64
64
  }