Skip to content

Commit

Permalink
chore(tsconfig.build): Fix type checking for tests etc (#11167)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored Aug 7, 2024
1 parent fdd0a14 commit f192815
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 143 deletions.
2 changes: 1 addition & 1 deletion packages/auth-providers/dbAuth/middleware/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"include": ["src/**/*"],
"references": [
{ "path": "../../../auth/tsconfig.build.json" },
{ "path": "../../../vite" }
{ "path": "../../../vite/tsconfig.build.json" }
]
}
2 changes: 1 addition & 1 deletion packages/auth-providers/supabase/middleware/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"include": ["src/**/*"],
"references": [
{ "path": "../../../auth/tsconfig.build.json" },
{ "path": "../../../vite" }
{ "path": "../../../vite/tsconfig.build.json" }
]
}
20 changes: 5 additions & 15 deletions packages/ogimage-gen/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,11 @@
"rootDir": "src",
"outDir": "dist"
},
"include": [
"src"
],
"include": ["src"],
"references": [
{
"path": "../project-config"
},
{
"path": "../vite"
},
{
"path": "../router/tsconfig.build.json"
},
{
"path": "../internal"
}
{ "path": "../project-config" },
{ "path": "../vite/tsconfig.build.json" },
{ "path": "../router/tsconfig.build.json" },
{ "path": "../internal" }
]
}
3 changes: 3 additions & 0 deletions packages/vite/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ await build({
},
buildOptions: {
...defaultBuildOptions,
tsconfig: 'tsconfig.build.json',
outdir: 'dist/cjs',
packages: 'external',
},
Expand All @@ -28,6 +29,7 @@ await build({
},
buildOptions: {
...defaultBuildOptions,
tsconfig: 'tsconfig.build.json',
format: 'esm',
packages: 'external',
},
Expand All @@ -51,6 +53,7 @@ await esbuild.build({
// https://github.com/evanw/esbuild/pull/2067
plugins: [commonjs()],
logLevel: 'info',
tsconfig: 'tsconfig.build.json',
})

// Place a package.json file with `type: commonjs` in the dist/cjs folder so
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"scripts": {
"build": "tsx build.ts && yarn build:types",
"build:pack": "yarn pack -o redwoodjs-vite.tgz",
"build:types": "tsc --build --verbose ./tsconfig.json",
"build:types": "tsc --build --verbose ./tsconfig.build.json",
"check:attw": "tsx ./attw.ts",
"test": "vitest run",
"check:package": "concurrently npm:check:attw yarn:publint",
Expand Down
2 changes: 0 additions & 2 deletions packages/vite/src/middleware/createMiddlewareRouter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ vi.mock('@redwoodjs/project-config', async () => {

const distRegisterMwMock = vi.fn()
vi.mock('/proj/web/dist/ssr/entry-server.mjs', () => {
console.log('using unix mock')
return {
registerMiddleware: distRegisterMwMock,
}
})
vi.mock('/C:/proj/web/dist/ssr/entry-server.mjs', () => {
console.log('using win32 mock')
return {
registerMiddleware: distRegisterMwMock,
}
Expand Down
18 changes: 15 additions & 3 deletions packages/vite/src/middleware/register.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { describe, expect, it, vitest } from 'vitest'
import { afterEach, beforeEach, describe, expect, it, vi, vitest } from 'vitest'

import type { Middleware, MiddlewareClass } from '@redwoodjs/web/middleware'
import {
MiddlewareRequest,
MiddlewareResponse,
} from '@redwoodjs/web/middleware'

import { addMiddlewareHandlers, chain, groupByRoutePatterns } from './register'
import type { MiddlewareReg } from './types'
import {
addMiddlewareHandlers,
chain,
groupByRoutePatterns,
} from './register.js'
import type { MiddlewareReg } from './types.js'

const fakeMiddleware: Middleware = vitest.fn()

Expand All @@ -26,6 +30,14 @@ class FakeClassMw implements MiddlewareClass {
}

describe('groupByRoutePatterns', () => {
beforeEach(() => {
vi.spyOn(console, 'error').mockImplementation(() => {})
})

afterEach(() => {
vi.mocked(console).error.mockRestore()
})

it('should group middleware by default *', () => {
const simpleExample = [fakeMiddleware]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@ import { excludeOnMatch } from '../vite-plugin-remove-from-bundle.js'

describe('excludeModule', () => {
it('should return true if idToExclude matches id', () => {
const loadOutput = excludeOnMatch([{
id: /router\/dist\/splash-page/,
}],
const loadOutput = excludeOnMatch(
[{ id: /router\/dist\/splash-page/ }],
'/Users/dac09/Experiments/splash-page-null-loader/node_modules/@redwoodjs/router/dist/splash-page.js?commonjs-exports',
)

expect(loadOutput).not.toEqual({
code: 'module.exports = null'
code: 'module.exports = null',
})
})

it("should return false if idToExclude doesn't match id", () => {
const loadOutput = excludeOnMatch([{
id: /bazinga-page/,
}],
'/Users/dac09/Experiments/splash-page-null-loader/node_modules/@redwoodjs/router/dist/params.js')
const loadOutput = excludeOnMatch(
[{ id: /bazinga-page/ }],
'/Users/dac09/Experiments/splash-page-null-loader/node_modules/@redwoodjs/router/dist/params.js',
)

expect(loadOutput).toEqual(null)
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { swapApolloProvider } from '../vite-plugin-swap-apollo-provider.js'
import { describe, it, expect } from 'vitest'

import { swapApolloProvider } from '../vite-plugin-swap-apollo-provider.js'

describe('excludeModule', () => {
it('should swap the import', async () => {
const plugin = swapApolloProvider()
Expand Down
Loading

0 comments on commit f192815

Please sign in to comment.