Skip to content

test: replace tsd with vitest type checking #6607

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
502 changes: 0 additions & 502 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions packages/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
"prebuild": "rm -rf lib",
"postbuild": "npx cpy \"src/**/*.yml\" \"lib/\"",
"build": "tsc",
"test:types": "tsd",
"test": "ava && tsd && vitest run",
"test:types": "vitest --typecheck",
"test": "ava && vitest --typecheck && vitest run",
"test:dev": "ava -w",
"test:ci": "run-p test:ci:*",
"test:ci:types": "tsd",
"test:ci:types": "vitest --typecheck",
"test:ci:ava": "c8 -r lcovonly -r text -r json ava",
"test:ci:vitest": "vitest run"
},
Expand Down Expand Up @@ -135,7 +135,6 @@
"process-exists": "^5.0.0",
"tinyspy": "^4.0.3",
"tmp-promise": "^3.0.2",
"tsd": "^0.32.0",
"vitest": "^3.0.0",
"yarn": "^1.22.22"
},
Expand Down
32 changes: 32 additions & 0 deletions packages/build/test-d/config/build.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { OnPreBuild } from '@netlify/build'
import { test, expectTypeOf } from 'vitest'

test('netlifyConfig.build types', () => {
const handler: OnPreBuild = ({ netlifyConfig: { build } }) => {
expectTypeOf(build.command).toEqualTypeOf<string | undefined>()
expectTypeOf(build.publish).toEqualTypeOf<string>()
expectTypeOf(build.base).toEqualTypeOf<string>()
expectTypeOf(build.services.testVar).toEqualTypeOf<unknown>()
expectTypeOf(build.ignore).toEqualTypeOf<string | undefined>()
expectTypeOf(build.edge_handlers).toEqualTypeOf<string | undefined>()
expectTypeOf(build.environment.TEST_VAR).toEqualTypeOf<string | undefined>()
}
expectTypeOf(handler).toEqualTypeOf<OnPreBuild>()
})

test('netlifyConfig.build.processing types', () => {
const handler: OnPreBuild = ({
netlifyConfig: {
build: { processing },
},
}) => {
expectTypeOf(processing.skip_processing).toEqualTypeOf<boolean | undefined>()
expectTypeOf(processing.css.bundle).toEqualTypeOf<boolean | undefined>()
expectTypeOf(processing.css.minify).toEqualTypeOf<boolean | undefined>()
expectTypeOf(processing.js.bundle).toEqualTypeOf<boolean | undefined>()
expectTypeOf(processing.js.minify).toEqualTypeOf<boolean | undefined>()
expectTypeOf(processing.html.pretty_url).toEqualTypeOf<boolean | undefined>()
expectTypeOf(processing.images.compress).toEqualTypeOf<boolean | undefined>()
}
expectTypeOf(handler).toEqualTypeOf<OnPreBuild>()
})
26 changes: 0 additions & 26 deletions packages/build/test-d/config/build.ts

This file was deleted.

22 changes: 22 additions & 0 deletions packages/build/test-d/config/functions.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { OnPreBuild } from '@netlify/build'
import { test, expectTypeOf } from 'vitest'

test('netlifyConfig.functions types', () => {
const handler: OnPreBuild = ({
netlifyConfig: {
functions: { '*': functions },
},
}) => {
expectTypeOf(functions.node_bundler).toExtend<string | undefined>()
expectTypeOf(functions.included_files).toEqualTypeOf<string[] | undefined>()

if (functions.node_bundler === 'esbuild') {
expectTypeOf(functions.external_node_modules).toEqualTypeOf<string[] | undefined>()
expectTypeOf(functions.ignored_node_modules).toEqualTypeOf<string[] | undefined>()
} else {
expectTypeOf(functions).not.toHaveProperty('external_node_modules')
expectTypeOf(functions).not.toHaveProperty('ignored_node_modules')
}
}
expectTypeOf(handler).toEqualTypeOf<OnPreBuild>()
})
19 changes: 0 additions & 19 deletions packages/build/test-d/config/functions.ts

This file was deleted.

31 changes: 31 additions & 0 deletions packages/build/test-d/config/inputs.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { OnPreBuild } from '@netlify/build'
import { test, expectTypeOf } from 'vitest'
import type { JSONValue } from '../../src/types/utils/json_value.js'

test('inputs generic types', () => {
const handler: OnPreBuild = (ctx) => {
expectTypeOf(ctx.inputs.testVar).toExtend<JSONValue | undefined>()
}
expectTypeOf(handler).toEqualTypeOf<OnPreBuild>()
})

test('inputs specific types', () => {
const handler: OnPreBuild<{ testVar: boolean }> = (ctx) => {
expectTypeOf(ctx.inputs.testVar).toEqualTypeOf<boolean>()
expectTypeOf(ctx.inputs).not.toHaveProperty('otherTestVar')
}
expectTypeOf(handler).toEqualTypeOf<OnPreBuild<{ testVar: boolean }>>()
})

test('inputs interface types', () => {
interface InputsInterface {
testVar: string
}

const handler: OnPreBuild<InputsInterface> = (ctx) => {
expectTypeOf(ctx.inputs.testVar).toEqualTypeOf<string>()
expectTypeOf(ctx.inputs).not.toHaveProperty('otherTestVar')
}

expectTypeOf(handler).toEqualTypeOf<OnPreBuild<InputsInterface>>()
})
21 changes: 0 additions & 21 deletions packages/build/test-d/config/inputs.ts

This file was deleted.

65 changes: 65 additions & 0 deletions packages/build/test-d/config/netlify_config.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import type { OnPreBuild } from '@netlify/build'
import { test, expectTypeOf } from 'vitest'
import type { JSONValue } from '../../src/types/utils/json_value.js'

test('netlifyConfig.plugins types', () => {
const handler: OnPreBuild = (ctx) => {
const [plugin] = ctx.netlifyConfig.plugins

expectTypeOf(plugin.package).toEqualTypeOf<string>()
expectTypeOf(plugin.inputs.testVar).toEqualTypeOf<JSONValue | undefined>()
}

expectTypeOf(handler).toEqualTypeOf<OnPreBuild>()
})

test('netlifyConfig.edge_functions types', () => {
const handler: OnPreBuild = (ctx) => {
const [edgeFunction] = ctx.netlifyConfig.edge_functions

expectTypeOf(edgeFunction.path).toExtend<string | undefined>()
expectTypeOf(edgeFunction.function).toEqualTypeOf<string>()
}

expectTypeOf(handler).toEqualTypeOf<OnPreBuild>()
})

test('netlifyConfig.headers types', () => {
const handler: OnPreBuild = (ctx) => {
const [header] = ctx.netlifyConfig.headers

expectTypeOf(header.for).toEqualTypeOf<string>()
expectTypeOf(header.values.testVar).toEqualTypeOf<string | string[] | undefined>()
}

expectTypeOf(handler).toEqualTypeOf<OnPreBuild>()
})

test('netlifyConfig.redirects types', () => {
const handler: OnPreBuild = (ctx) => {
const [redirect] = ctx.netlifyConfig.redirects

expectTypeOf(redirect.from).toEqualTypeOf<string>()
expectTypeOf(redirect.to).toEqualTypeOf<string | undefined>()
expectTypeOf(redirect.status).toEqualTypeOf<number | undefined>()
expectTypeOf(redirect.force).toEqualTypeOf<boolean | undefined>()
expectTypeOf(redirect.signed).toEqualTypeOf<string | undefined>()

if (redirect.query !== undefined) {
expectTypeOf(redirect.query.testVar).toEqualTypeOf<string | undefined>()
}

if (redirect.headers !== undefined) {
expectTypeOf(redirect.headers.testVar).toEqualTypeOf<string | undefined>()
}

if (redirect.conditions !== undefined) {
expectTypeOf(redirect.conditions.Language).toEqualTypeOf<readonly string[] | undefined>()
expectTypeOf(redirect.conditions.Cookie).toEqualTypeOf<readonly string[] | undefined>()
expectTypeOf(redirect.conditions.Country).toEqualTypeOf<readonly string[] | undefined>()
expectTypeOf(redirect.conditions.Role).toEqualTypeOf<readonly string[] | undefined>()
}
}

expectTypeOf(handler).toEqualTypeOf<OnPreBuild>()
})
58 changes: 0 additions & 58 deletions packages/build/test-d/config/netlify_config.ts

This file was deleted.

37 changes: 37 additions & 0 deletions packages/build/test-d/netlify_plugin.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { NetlifyPlugin, OnPreBuild, OnBuild, OnPostBuild, OnError, OnSuccess, OnEnd } from '@netlify/build'
import { test, expectTypeOf } from 'vitest'

test('events noop types', () => {
const noop = () => {}

expectTypeOf(noop).toExtend<OnPreBuild>()
expectTypeOf(noop).toExtend<OnBuild>()
expectTypeOf(noop).toExtend<OnPostBuild>()
expectTypeOf(noop).toExtend<OnError>()
expectTypeOf(noop).toExtend<OnSuccess>()
expectTypeOf(noop).toExtend<OnEnd>()

const plugin: NetlifyPlugin = {
onPreBuild: noop,
onBuild: noop,
onPostBuild: noop,
onError: noop,
onSuccess: noop,
onEnd: noop,
}
expectTypeOf(plugin).toEqualTypeOf<NetlifyPlugin>()
})

test('onError argument types', () => {
const handler: OnError = ({ error }) => {
expectTypeOf(error).toEqualTypeOf<Error>()
}
expectTypeOf(handler).toEqualTypeOf<OnError>()
})

test('onEnd argument types', () => {
const handler: OnEnd = ({ error }) => {
expectTypeOf(error).toEqualTypeOf<Error | undefined>()
}
expectTypeOf(handler).toEqualTypeOf<OnEnd>()
})
22 changes: 0 additions & 22 deletions packages/build/test-d/netlify_plugin.ts

This file was deleted.

29 changes: 29 additions & 0 deletions packages/build/test-d/netlify_plugin_options.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { NetlifyPluginConstants, NetlifyPluginOptions, OnPreBuild } from '@netlify/build'
import { test, expectTypeOf } from 'vitest'
import type { JSONValue } from '../src/types/utils/json_value.js'

test('constants types', () => {
const handler: OnPreBuild = ({ constants }) => {
expectTypeOf(constants).toEqualTypeOf<NetlifyPluginConstants>()
expectTypeOf(constants.CONFIG_PATH).toEqualTypeOf<string | undefined>()
expectTypeOf(constants.PUBLISH_DIR).toEqualTypeOf<string>()
expectTypeOf(constants.FUNCTIONS_SRC).toEqualTypeOf<string | undefined>()
expectTypeOf(constants.INTERNAL_EDGE_FUNCTIONS_SRC).toEqualTypeOf<string | undefined>()
expectTypeOf(constants.INTERNAL_FUNCTIONS_SRC).toEqualTypeOf<string | undefined>()
expectTypeOf(constants.FUNCTIONS_DIST).toEqualTypeOf<string>()
expectTypeOf(constants.EDGE_FUNCTIONS_SRC).toEqualTypeOf<string | undefined>()
expectTypeOf(constants.EDGE_FUNCTIONS_DIST).toEqualTypeOf<string>()
expectTypeOf(constants.IS_LOCAL).toEqualTypeOf<boolean>()
expectTypeOf(constants.NETLIFY_BUILD_VERSION).toEqualTypeOf<string>()
expectTypeOf(constants.SITE_ID).toEqualTypeOf<string>()
}
expectTypeOf(handler).toEqualTypeOf<OnPreBuild>()
})

test('package.json types', () => {
const handler: OnPreBuild = ({ packageJson }) => {
expectTypeOf(packageJson).toEqualTypeOf<NetlifyPluginOptions['packageJson']>()
expectTypeOf(packageJson.version).toEqualTypeOf<JSONValue | undefined>()
}
expectTypeOf(handler).toEqualTypeOf<OnPreBuild>()
})
Loading
Loading