Skip to content

Commit 8ee88c9

Browse files
committed
refactor: enable typechecking on tests
1 parent 9eb7cb2 commit 8ee88c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+908
-721
lines changed

Diff for: eslint.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export default tseslint.config(
152152
'n/no-unsupported-features/node-builtins': [
153153
'error',
154154
{
155-
ignores: ['FormData', 'ReadableStream', 'Response', 'fetch', 'fs/promises.cp'],
155+
ignores: ['FormData', 'ReadableStream', 'Response', 'Request', 'fetch', 'fs/promises.cp'],
156156
},
157157
],
158158
},

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
"postinstall": "npm run build && node ./scripts/postinstall.js",
6060
"prepublishOnly": "node ./scripts/prepare-for-publish.js",
6161
"certs": "openssl req -x509 -out localhost.crt -keyout localhost.key -newkey rsa:2048 -nodes -sha256 -subj \"/CN=localhost\" -extensions EXT -config certconf",
62-
"typecheck": "tsc"
62+
"typecheck": "tsc",
63+
"typecheck:watch": "tsc --watch"
6364
},
6465
"dependencies": {
6566
"@fastify/static": "7.0.4",

Diff for: tests/integration/commands/blobs/blobs-delete.test.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ describe('blobs:delete command', () => {
125125
await runMockProgram(['', '', 'blobs:delete', storeName, key])
126126
} catch (error) {
127127
// We expect the process to exit, so this is fine
128-
expect(error.message).toContain('process.exit unexpectedly called')
128+
expect(error).toBeInstanceOf(Error)
129+
expect((error as Error).message).toContain('process.exit unexpectedly called')
129130
}
130131

131132
expect(promptSpy).toHaveBeenCalledWith({
@@ -181,7 +182,8 @@ describe('blobs:delete command', () => {
181182
try {
182183
await runMockProgram(['', '', 'blobs:delete', storeName, key, '--force'])
183184
} catch (error) {
184-
expect(error.message).toContain(
185+
expect(error).toBeInstanceOf(Error)
186+
expect((error as Error).message).toContain(
185187
`Could not delete blob ${chalk.yellow(key)} from store ${chalk.yellow(storeName)}`,
186188
)
187189
}
@@ -223,7 +225,7 @@ describe('blobs:delete command', () => {
223225
})
224226

225227
test('should not show prompt for CI/CD', async () => {
226-
setCI(true)
228+
setCI('true')
227229
await withMockApi(routes, async ({ apiUrl }) => {
228230
Object.assign(process.env, getEnvironmentVariables({ apiUrl }))
229231

Diff for: tests/integration/commands/blobs/blobs-set.test.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ describe('blobs:set command', () => {
157157
await runMockProgram(['', '', 'blobs:set', storeName, key, newValue])
158158
} catch (error) {
159159
// We expect the process to exit, so this is fine
160-
expect(error.message).toContain('process.exit unexpectedly called with "0"')
160+
expect(error).toBeInstanceOf(Error)
161+
expect((error as Error).message).toContain('process.exit unexpectedly called with "0"')
161162
}
162163

163164
expect(promptSpy).toHaveBeenCalledWith({
@@ -213,7 +214,8 @@ describe('blobs:set command', () => {
213214
try {
214215
await runMockProgram(['', '', 'blobs:set', storeName, key, newValue, '--force'])
215216
} catch (error) {
216-
expect(error.message).toContain(
217+
expect(error).toBeInstanceOf(Error)
218+
expect((error as Error).message).toContain(
217219
`Could not set blob ${chalk.yellow(key)} in store ${chalk.yellow(storeName)}`,
218220
)
219221
}
@@ -256,7 +258,7 @@ describe('blobs:set command', () => {
256258
})
257259

258260
test('should not show prompt in a ci/cd environment', async () => {
259-
setCI(true)
261+
setCI('true')
260262
await withMockApi(routes, async ({ apiUrl }) => {
261263
Object.assign(process.env, getEnvironmentVariables({ apiUrl }))
262264

Diff for: tests/integration/commands/build/build-program.test.js renamed to tests/integration/commands/build/build-program.test.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ import process from 'process'
22

33
import { expect, beforeEach, afterAll, describe, test, vi } from 'vitest'
44

5-
import BaseCommand from '../../../../src/commands/base-command.ts'
6-
import { createBuildCommand } from '../../../../src/commands/build/index.ts'
5+
import BaseCommand from '../../../../src/commands/base-command.js'
6+
import { createBuildCommand } from '../../../../src/commands/build/index.js'
77
import { getEnvironmentVariables, withMockApi } from '../../utils/mock-api.js'
8-
import { withSiteBuilder } from '../../utils/site-builder.ts'
8+
import { withSiteBuilder } from '../../utils/site-builder.js'
99

1010
let configOptions = {}
1111

1212
vi.mock('@netlify/config', async (importOriginal) => {
13-
const original = await importOriginal()
13+
const original = (await importOriginal()) as typeof import('@netlify/config')
1414
return {
1515
...original,
16-
resolveConfig: (options) => {
16+
resolveConfig: (options: object) => {
1717
configOptions = options
1818
return original.resolveConfig(options)
1919
},
@@ -60,6 +60,7 @@ describe('command/build', () => {
6060

6161
test('should pass feature flags to @netlify/config', async (t) => {
6262
// this ensures that the process.exit does not exit the test process
63+
// @ts-expect-error(ndhoule): Cannot mark the return value on this as as `never`
6364
vi.spyOn(process, 'exit').mockImplementation((code) => {
6465
expect(code).toBe(0)
6566
})
@@ -72,11 +73,11 @@ describe('command/build', () => {
7273
await builder.withNetlifyToml({ config: {} }).withStateFile({ siteId: siteInfo.id }).build()
7374

7475
await createBuildCommand(new BaseCommand('netlify')).parseAsync(['', '', 'build'])
75-
expect(configOptions.featureFlags).toEqual(siteInfo.feature_flags)
76-
expect(configOptions.accountId).toEqual(siteInfo.account_id)
76+
expect(configOptions).toHaveProperty('featureFlags', siteInfo.feature_flags)
77+
expect(configOptions).toHaveProperty('accountId', siteInfo.account_id)
7778

7879
await createBuildCommand(new BaseCommand('netlify')).parseAsync(['', '', 'build', '--offline'])
79-
expect(configOptions.featureFlags, 'should not call API in offline mode').toEqual({})
80+
expect(configOptions).toHaveProperty('featureFlags', {})
8081
})
8182
})
8283
})

Diff for: tests/integration/commands/build/build.test.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import path, { join } from 'path'
22
import process from 'process'
33

44
import execa from 'execa'
5-
import { describe, expect, test } from 'vitest'
5+
import { describe, expect, test, type TaskContext, type TestContext } from 'vitest'
66

77
import { callCli } from '../../utils/call-cli.js'
88
import { cliPath } from '../../utils/cli-path.js'
9-
import { FixtureTestContext, setupFixtureTests } from '../../utils/fixture.ts'
9+
import { FixtureTestContext, setupFixtureTests } from '../../utils/fixture.js'
1010
import { CONFIRM, handleQuestions } from '../../utils/handle-questions.js'
1111
import { withMockApi } from '../../utils/mock-api.js'
12-
import { withSiteBuilder } from '../../utils/site-builder.ts'
12+
import { withSiteBuilder } from '../../utils/site-builder.js'
1313

1414
const defaultEnvs = {
1515
NETLIFY_AUTH_TOKEN: 'fake-token',
@@ -22,17 +22,18 @@ const defaultEnvs = {
2222
* - that its output contains `output`
2323
*/
2424
const runBuildCommand = async function (
25-
t,
26-
cwd,
25+
t: TaskContext & TestContext,
26+
cwd: string,
2727
options: Partial<{
2828
exitCode: number
2929
flags: string[]
30-
output: any
30+
expectedExitCode?: number | undefined
31+
output: string | RegExp | (string | RegExp)[]
3132
env: Record<string, string>
3233
apiUrl: string
3334
}> = {},
3435
) {
35-
let { apiUrl, env = defaultEnvs, exitCode: expectedExitCode = 0, flags = [], output: outputs } = options
36+
let { apiUrl, env = defaultEnvs, exitCode: expectedExitCode = 0, flags = [], output: outputs = [] } = options
3637
const { all, exitCode } = await execa(cliPath, ['build', ...flags], {
3738
reject: false,
3839
cwd,

Diff for: tests/integration/commands/completion/completion-install.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, test, beforeAll, afterAll } from 'vitest'
1+
import { describe, test, beforeAll, afterAll } from 'vitest'
22
import fs from 'fs'
33
import { rm } from 'fs/promises'
44
import { temporaryDirectory } from 'tempy'
@@ -9,9 +9,9 @@ import { join } from 'path'
99
import { TABTAB_CONFIG_LINE, AUTOLOAD_COMPINIT } from '../../../../src/utils/command-helpers.js'
1010

1111
describe('completion:install command', () => {
12-
let tempDir
13-
let zshConfigPath
14-
let options
12+
let tempDir: string
13+
let zshConfigPath: string
14+
let options: execa.Options
1515

1616
beforeAll(() => {
1717
tempDir = temporaryDirectory()
@@ -25,7 +25,7 @@ describe('completion:install command', () => {
2525

2626
test.skipIf(process.env.SHELL !== '/bin/zsh')(
2727
'should add compinit to .zshrc when user confirms prompt',
28-
async (t) => {
28+
async ({ expect }) => {
2929
fs.writeFileSync(zshConfigPath, TABTAB_CONFIG_LINE)
3030
const childProcess = execa(cliPath, ['completion:install'], options)
3131

@@ -52,7 +52,7 @@ describe('completion:install command', () => {
5252

5353
test.skipIf(process.env.SHELL !== '/bin/zsh')(
5454
'should not add compinit to .zshrc when user does not confirm prompt',
55-
async (t) => {
55+
async ({ expect }) => {
5656
fs.writeFileSync(zshConfigPath, TABTAB_CONFIG_LINE)
5757
const childProcess = execa(cliPath, ['completion:install'], options)
5858

0 commit comments

Comments
 (0)