Skip to content

Commit

Permalink
Merge branch 'main' into fix/enhance-error-apollo-suspense
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored Dec 27, 2023
2 parents dba3868 + 3d1179a commit f1e9a42
Show file tree
Hide file tree
Showing 12 changed files with 284 additions and 223 deletions.
3 changes: 2 additions & 1 deletion .github/actions/detect-changes/cases/ssr.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export function ssrChanged(changedFiles){
for (const changedFile of changedFiles) {
if (
changedFile.startsWith('tasks/smoke-tests/streaming-ssr') ||
changedFile.startsWith('tasks/smoke-tests/basePlaywright.config.ts') ||
changedFile === 'tasks/smoke-tests/basePlaywright.config.ts' ||
changedFile === 'tasks/test-project/codemods/delayedPage.js' ||
changedFile.startsWith('packages/internal/') ||
changedFile.startsWith('packages/project-config/') ||
changedFile.startsWith('packages/web/') ||
Expand Down
13 changes: 12 additions & 1 deletion .github/actions/detect-changes/detectChanges.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async function getChangedFiles(page = 1) {
})

const json = await resp.json()
const files = json.map((file) => file.filename) || []
const files = json?.map((file) => file.filename) || []

changedFiles = changedFiles.concat(files)

Expand Down Expand Up @@ -78,6 +78,17 @@ async function main() {
const changedFiles = await getChangedFiles()
console.log(`${changedFiles.length} changed files`)

if (changedFiles.length === 0) {
console.log(
'No changed files found. Something must have gone wrong. Fall back to ' +
'running all tests.'
)
core.setOutput('onlydocs', false)
core.setOutput('rsc', true)
core.setOutput('ssr', true)
return
}

if (!hasCodeChanges(changedFiles)) {
console.log('No code changes detected, only docs')
core.setOutput('onlydocs', true)
Expand Down
2 changes: 1 addition & 1 deletion packages/api-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@babel/core": "^7.22.20",
"@types/aws-lambda": "8.10.126",
"@types/lodash": "4.14.201",
"@types/qs": "6.9.10",
"@types/qs": "6.9.11",
"@types/split2": "4.2.3",
"@types/yargs": "17.0.32",
"aws-lambda": "1.0.7",
Expand Down
208 changes: 4 additions & 204 deletions packages/babel-config/src/__tests__/common.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import { vol } from 'memfs'

import { ensurePosixPath } from '@redwoodjs/project-config'

import {
getCommonPlugins,
getPathsFromTypeScriptConfig,
parseTypeScriptConfigFiles,
} from '../common'

jest.mock('fs', () => require('memfs').fs)
import { getCommonPlugins } from '../common'

const redwoodProjectPath = '/redwood-app'
process.env.RWJS_CWD = redwoodProjectPath
Expand All @@ -17,11 +9,10 @@ afterEach(() => {
vol.reset()
})

describe('common', () => {
it("common plugins haven't changed unintentionally", () => {
const commonPlugins = getCommonPlugins()
test("common plugins haven't changed unintentionally", () => {
const commonPlugins = getCommonPlugins()

expect(commonPlugins).toMatchInlineSnapshot(`
expect(commonPlugins).toMatchInlineSnapshot(`
[
[
"@babel/plugin-transform-class-properties",
Expand All @@ -43,195 +34,4 @@ describe('common', () => {
],
]
`)
})

describe('TypeScript config files', () => {
it("returns `null` if it can't find TypeScript config files", () => {
vol.fromNestedJSON(
{
'redwood.toml': '',
api: {},
web: {},
},
redwoodProjectPath
)

const typeScriptConfig = parseTypeScriptConfigFiles()
expect(typeScriptConfig).toHaveProperty('api', null)
expect(typeScriptConfig).toHaveProperty('web', null)
})

it('finds and parses tsconfig.json files', () => {
const apiTSConfig = '{"compilerOptions": {"noEmit": true}}'
const webTSConfig = '{"compilerOptions": {"allowJs": true}}'

vol.fromNestedJSON(
{
'redwood.toml': '',
api: {
'tsconfig.json': apiTSConfig,
},
web: {
'tsconfig.json': webTSConfig,
},
},
redwoodProjectPath
)

const typeScriptConfig = parseTypeScriptConfigFiles()
expect(typeScriptConfig.api).toMatchObject(JSON.parse(apiTSConfig))
expect(typeScriptConfig.web).toMatchObject(JSON.parse(webTSConfig))
})

it('finds and parses jsconfig.json files', () => {
const apiJSConfig = '{"compilerOptions": {"noEmit": true}}'
const webJSConfig = '{"compilerOptions": {"allowJs": true}}'

vol.fromNestedJSON(
{
'redwood.toml': '',
api: {
'jsconfig.json': apiJSConfig,
},
web: {
'jsconfig.json': webJSConfig,
},
},
redwoodProjectPath
)

const typeScriptConfig = parseTypeScriptConfigFiles()
expect(typeScriptConfig.api).toMatchObject(JSON.parse(apiJSConfig))
expect(typeScriptConfig.web).toMatchObject(JSON.parse(webJSConfig))
})

describe('getPathsFromTypeScriptConfig', () => {
it("returns an empty object if there's no TypeScript config files", () => {
vol.fromNestedJSON(
{
'redwood.toml': '',
api: {},
web: {},
},
redwoodProjectPath
)

const typeScriptConfig = parseTypeScriptConfigFiles()

const apiPaths = getPathsFromTypeScriptConfig(typeScriptConfig.api)
expect(apiPaths).toMatchObject({})

const webPaths = getPathsFromTypeScriptConfig(typeScriptConfig.web)
expect(webPaths).toMatchObject({})
})

it("returns an empty object if there's no compilerOptions, baseUrl, or paths", () => {
const apiTSConfig = '{}'
const webTSConfig = '{"compilerOptions":{"allowJs": true}}'

vol.fromNestedJSON(
{
'redwood.toml': '',
api: {
'tsconfig.json': apiTSConfig,
},
web: {
'tsconfig.json': webTSConfig,
},
},
redwoodProjectPath
)

const typeScriptConfig = parseTypeScriptConfigFiles()

const apiPaths = getPathsFromTypeScriptConfig(typeScriptConfig.api)
expect(apiPaths).toMatchInlineSnapshot(`{}`)

const webPaths = getPathsFromTypeScriptConfig(typeScriptConfig.web)
expect(webPaths).toMatchInlineSnapshot(`{}`)
})

it('excludes "src/*", "$api/*", "types/*", and "@redwoodjs/testing"', () => {
const apiTSConfig =
'{"compilerOptions":{"baseUrl":"./","paths":{"src/*":["./src/*","../.redwood/types/mirror/api/src/*"],"types/*":["./types/*","../types/*"],"@redwoodjs/testing":["../node_modules/@redwoodjs/testing/api"]}}}'
const webTSConfig =
'{"compilerOptions":{"baseUrl":"./","paths":{"src/*":["./src/*","../.redwood/types/mirror/web/src/*"],"$api/*":[ "../api/*" ],"types/*":["./types/*", "../types/*"],"@redwoodjs/testing":["../node_modules/@redwoodjs/testing/web"]}}}'

vol.fromNestedJSON(
{
'redwood.toml': '',
api: {
'tsconfig.json': apiTSConfig,
},
web: {
'tsconfig.json': webTSConfig,
},
},
redwoodProjectPath
)

const typeScriptConfig = parseTypeScriptConfigFiles()

const apiPaths = getPathsFromTypeScriptConfig(typeScriptConfig.api)
expect(apiPaths).toMatchInlineSnapshot(`{}`)

const webPaths = getPathsFromTypeScriptConfig(typeScriptConfig.web)
expect(webPaths).toMatchInlineSnapshot(`{}`)
})

it('gets and formats paths', () => {
const apiTSConfig =
'{"compilerOptions":{"baseUrl":"./","paths":{"@services/*":["./src/services/*"]}}}'
const webTSConfig =
'{"compilerOptions":{"baseUrl":"./","paths":{"@ui/*":["./src/ui/*"]}}}'

vol.fromNestedJSON(
{
'redwood.toml': '',
api: {
'tsconfig.json': apiTSConfig,
},
web: {
'tsconfig.json': webTSConfig,
},
},
redwoodProjectPath
)

const typeScriptConfig = parseTypeScriptConfigFiles()

const apiPaths = getPathsFromTypeScriptConfig(typeScriptConfig.api)
expect(ensurePosixPath(apiPaths['@services'])).toMatchInlineSnapshot(
`"src/services"`
)

const webPaths = getPathsFromTypeScriptConfig(typeScriptConfig.web)
expect(ensurePosixPath(webPaths['@ui'])).toMatchInlineSnapshot(
`"src/ui"`
)
})
})

it('handles invalid JSON', () => {
const apiTSConfig =
'{"compilerOptions": {"noEmit": true,"allowJs": true,"esModuleInterop": true,"target": "esnext","module": "esnext","moduleResolution": "node","baseUrl": "./","rootDirs": ["./src","../.redwood/types/mirror/api/src"],"paths": {"src/*": ["./src/*","../.redwood/types/mirror/api/src/*"],"types/*": ["./types/*", "../types/*"],"@redwoodjs/testing": ["../node_modules/@redwoodjs/testing/api"]},"typeRoots": ["../node_modules/@types","./node_modules/@types"],"types": ["jest"],},"include": ["src","../.redwood/types/includes/all-*","../.redwood/types/includes/api-*","../types"]}'
const webTSConfig =
'{"compilerOptions": {"noEmit": true,"allowJs": true,"esModuleInterop": true,"target": "esnext","module": "esnext","moduleResolution": "node","baseUrl": "./","rootDirs": ["./src","../.redwood/types/mirror/web/src","../api/src","../.redwood/types/mirror/api/src"],"paths": {"src/*": ["./src/*","../.redwood/types/mirror/web/src/*","../api/src/*","../.redwood/types/mirror/api/src/*"],"$api/*": [ "../api/*" ],"types/*": ["./types/*", "../types/*"],"@redwoodjs/testing": ["../node_modules/@redwoodjs/testing/web"]},"typeRoots": ["../node_modules/@types", "./node_modules/@types", "../node_modules/@testing-library"],"types": ["jest-dom"],"jsx": "preserve",},"include": ["src","../.redwood/types/includes/all-*","../.redwood/types/includes/web-*","../types","./types"]}'

vol.fromNestedJSON(
{
'redwood.toml': '',
api: {
'tsconfig.json': apiTSConfig,
},
web: {
'tsconfig.json': webTSConfig,
},
},
redwoodProjectPath
)

expect(parseTypeScriptConfigFiles).not.toThrow()
})
})
})
Loading

0 comments on commit f1e9a42

Please sign in to comment.