Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: switch some more packages to vitest #9867

Merged
merged 5 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/mailer/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"build:types": "tsc --build --verbose",
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx\" --ignore dist --exec \"yarn build\"",
"prepublishOnly": "NODE_ENV=production yarn build",
"test": "jest src",
"test:watch": "yarn test --watch"
"test": "vitest run src",
"test:watch": "vitest watch src"
},
"jest": {
"testPathIgnorePatterns": [
Expand All @@ -30,8 +30,8 @@
"@redwoodjs/api": "6.0.7",
"esbuild": "0.19.9",
"fast-glob": "3.3.2",
"jest": "29.7.0",
"typescript": "5.3.3"
"typescript": "5.3.3",
"vitest": "1.2.1"
},
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
}
57 changes: 34 additions & 23 deletions packages/mailer/core/src/__tests__/mailer.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import {
vi,
describe,
test,
expect,
beforeAll,
afterAll,
beforeEach,
afterEach,
} from 'vitest'

import { AbstractMailHandler } from '../handler'
import { Mailer } from '../mailer'
import { AbstractMailRenderer } from '../renderer'
Expand Down Expand Up @@ -61,13 +72,13 @@ describe('Uses the correct modes', () => {

beforeAll(() => {
// prevent console output
jest.spyOn(console, 'log').mockImplementation(() => {})
jest.spyOn(console, 'warn').mockImplementation(() => {})
jest.spyOn(console, 'debug').mockImplementation(() => {})
vi.spyOn(console, 'log').mockImplementation(() => {})
vi.spyOn(console, 'warn').mockImplementation(() => {})
vi.spyOn(console, 'debug').mockImplementation(() => {})
})

afterAll(() => {
jest.restoreAllMocks()
vi.restoreAllMocks()
})

describe('starts in test mode', () => {
Expand Down Expand Up @@ -131,7 +142,7 @@ describe('Uses the correct modes', () => {
},
})
}).toThrowErrorMatchingInlineSnapshot(
`"Invalid 'when' configuration for test mode"`
`[Error: Invalid 'when' configuration for test mode]`
)

expect(() => {
Expand All @@ -143,7 +154,7 @@ describe('Uses the correct modes', () => {
},
})
}).toThrowErrorMatchingInlineSnapshot(
`"Invalid 'when' configuration for test mode"`
`[Error: Invalid 'when' configuration for test mode]`
)
})
})
Expand Down Expand Up @@ -224,7 +235,7 @@ describe('Uses the correct modes', () => {
},
})
}).toThrowErrorMatchingInlineSnapshot(
`"Invalid 'when' configuration for development mode"`
`[Error: Invalid 'when' configuration for development mode]`
)

expect(() => {
Expand All @@ -239,7 +250,7 @@ describe('Uses the correct modes', () => {
},
})
}).toThrowErrorMatchingInlineSnapshot(
`"Invalid 'when' configuration for development mode"`
`[Error: Invalid 'when' configuration for development mode]`
)
})
})
Expand Down Expand Up @@ -310,7 +321,7 @@ describe('Uses the correct modes', () => {

describe('warns about null handlers', () => {
beforeAll(() => {
jest.spyOn(console, 'warn').mockImplementation(() => {})
vi.spyOn(console, 'warn').mockImplementation(() => {})
})

test('test', () => {
Expand Down Expand Up @@ -344,7 +355,7 @@ describe('Uses the correct modes', () => {

describe('attempts to use fallback handlers', () => {
beforeAll(() => {
jest.spyOn(console, 'warn').mockImplementation(() => {})
vi.spyOn(console, 'warn').mockImplementation(() => {})
})

test('test', () => {
Expand Down Expand Up @@ -388,7 +399,7 @@ describe('Uses the correct modes', () => {
},
})
}).toThrowErrorMatchingInlineSnapshot(
`"The specified test handler 'handlerC' is not defined"`
`[Error: The specified test handler 'handlerC' is not defined]`
)
})
test('development', () => {
Expand All @@ -402,7 +413,7 @@ describe('Uses the correct modes', () => {
},
})
}).toThrowErrorMatchingInlineSnapshot(
`"The specified development handler 'handlerC' is not defined"`
`[Error: The specified development handler 'handlerC' is not defined]`
)
})
test('production', () => {
Expand All @@ -422,7 +433,7 @@ describe('Uses the correct modes', () => {
},
})
}).toThrowErrorMatchingInlineSnapshot(
`"The specified default handler 'handlerC' is not defined"`
`[Error: The specified default handler 'handlerC' is not defined]`
)
})
})
Expand All @@ -442,7 +453,7 @@ describe('Uses the correct modes', () => {
},
})
}).toThrowErrorMatchingInlineSnapshot(
`"The specified default renderer 'rendererC' is not defined"`
`[Error: The specified default renderer 'rendererC' is not defined]`
)
})
test('development', () => {
Expand All @@ -459,7 +470,7 @@ describe('Uses the correct modes', () => {
},
})
}).toThrowErrorMatchingInlineSnapshot(
`"The specified default renderer 'rendererC' is not defined"`
`[Error: The specified default renderer 'rendererC' is not defined]`
)
})
test('production', () => {
Expand All @@ -479,13 +490,13 @@ describe('Uses the correct modes', () => {
},
})
}).toThrowErrorMatchingInlineSnapshot(
`"The specified default renderer 'rendererC' is not defined"`
`[Error: The specified default renderer 'rendererC' is not defined]`
)
})
})

describe('calls the correct handler and renderer function', () => {
jest.spyOn(console, 'debug').mockImplementation(() => {})
vi.spyOn(console, 'debug').mockImplementation(() => {})

describe('test', () => {
const testHandler = new MockMailHandler()
Expand Down Expand Up @@ -522,12 +533,12 @@ describe('Uses the correct modes', () => {
const handlerKeys = Object.keys(mailer.handlers)
for (let i = 0; i < handlerKeys.length; i++) {
const key = handlerKeys[i]
jest.spyOn(mailer.handlers[key], 'send')
vi.spyOn(mailer.handlers[key], 'send')
}
const rendererKeys = Object.keys(mailer.renderers)
for (let i = 0; i < rendererKeys.length; i++) {
const key = rendererKeys[i]
jest.spyOn(mailer.renderers[key], 'render')
vi.spyOn(mailer.renderers[key], 'render')
}
})

Expand Down Expand Up @@ -622,12 +633,12 @@ describe('Uses the correct modes', () => {
const handlerKeys = Object.keys(mailer.handlers)
for (let i = 0; i < handlerKeys.length; i++) {
const key = handlerKeys[i]
jest.spyOn(mailer.handlers[key], 'send')
vi.spyOn(mailer.handlers[key], 'send')
}
const rendererKeys = Object.keys(mailer.renderers)
for (let i = 0; i < rendererKeys.length; i++) {
const key = rendererKeys[i]
jest.spyOn(mailer.renderers[key], 'render')
vi.spyOn(mailer.renderers[key], 'render')
}
})

Expand Down Expand Up @@ -723,12 +734,12 @@ describe('Uses the correct modes', () => {
const handlerKeys = Object.keys(mailer.handlers)
for (let i = 0; i < handlerKeys.length; i++) {
const key = handlerKeys[i]
jest.spyOn(mailer.handlers[key], 'send')
vi.spyOn(mailer.handlers[key], 'send')
}
const rendererKeys = Object.keys(mailer.renderers)
for (let i = 0; i < rendererKeys.length; i++) {
const key = rendererKeys[i]
jest.spyOn(mailer.renderers[key], 'render')
vi.spyOn(mailer.renderers[key], 'render')
}
})

Expand Down
8 changes: 5 additions & 3 deletions packages/mailer/core/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, test, expect } from 'vitest'

import type { MailerDefaults } from '../types'
import {
constructCompleteSendOptions,
Expand Down Expand Up @@ -120,7 +122,7 @@ describe('constructCompleteSendOptions', () => {
},
blankDefaults
)
}).toThrowErrorMatchingInlineSnapshot(`"Missing from address"`)
}).toThrowErrorMatchingInlineSnapshot(`[Error: Missing from address]`)

expect(() => {
constructCompleteSendOptions(
Expand Down Expand Up @@ -153,7 +155,7 @@ describe('constructCompleteSendOptions', () => {
},
blankDefaults
)
}).toThrowErrorMatchingInlineSnapshot(`"Missing to address"`)
}).toThrowErrorMatchingInlineSnapshot(`[Error: Missing to address]`)

expect(() => {
constructCompleteSendOptions(
Expand All @@ -176,7 +178,7 @@ describe('constructCompleteSendOptions', () => {
},
blankDefaults
)
}).toThrowErrorMatchingInlineSnapshot(`"Missing subject"`)
}).toThrowErrorMatchingInlineSnapshot(`[Error: Missing subject]`)

expect(() => {
constructCompleteSendOptions(
Expand Down
6 changes: 3 additions & 3 deletions packages/record/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx\" --ignore dist --exec \"yarn build\"",
"datamodel:parse": "node src/scripts/parse.js",
"prepublishOnly": "NODE_ENV=production yarn build",
"test": "jest src",
"test:watch": "yarn test --watch"
"test": "vitest run src",
"test:watch": "vitest watch src"
},
"jest": {
"testPathIgnorePatterns": [
Expand All @@ -38,7 +38,7 @@
"@babel/core": "^7.22.20",
"@prisma/internals": "5.7.0",
"esbuild": "0.19.9",
"jest": "29.7.0"
"vitest": "1.2.1"
},
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
}
Loading
Loading