Skip to content
Merged
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
3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ export default tseslint.config(

// Custom assertion functions
'assertNetlifyToml',

// Vitest type testing functions
'expectTypeOf',
],
},
],
Expand Down
13 changes: 13 additions & 0 deletions packages/functions/src/global-types.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { describe, test, expectTypeOf } from 'vitest'
import type { NetlifyGlobal } from '@netlify/types'

// Import the main module to ensure global augmentation is loaded
import './main.js'

describe('Netlify global type declaration regression test', () => {
test('should augment global scope with `Netlify` global', () => {
expectTypeOf<typeof Netlify>().toEqualTypeOf<NetlifyGlobal>()
expectTypeOf<typeof Netlify>().toHaveProperty('env')
expectTypeOf<typeof Netlify>().toHaveProperty('context')
})
})
6 changes: 6 additions & 0 deletions packages/functions/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import type { NetlifyGlobal } from '@netlify/types'

declare global {
const Netlify: NetlifyGlobal
}

export { builder } from './lib/builder.js'
export { purgeCache } from './lib/purge_cache.js'
export { schedule } from './lib/schedule.js'
Expand Down
1 change: 1 addition & 0 deletions packages/functions/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"removeComments": false,
"strict": true,
"moduleResolution": "node",
"skipLibCheck": true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See explanation in 33b8ec5 😅

"forceConsistentCasingInFileNames": true
},
"include": ["src", "dev"]
Expand Down
3 changes: 3 additions & 0 deletions packages/functions/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ export default defineConfig({
test: {
include: ['(src|dev)/**/*.test.ts'],
testTimeout: 30_000,
typecheck: {
enabled: true,
},
},
})
6 changes: 3 additions & 3 deletions packages/types/src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { fileURLToPath } from 'node:url'

import { expect, expectTypeOf, test } from 'vitest'

import { Context, NetlifyGlobal } from './main.js'
import type { Context, NetlifyGlobal } from './main.js'
import * as main from './main.js'

test('Exports types', () => {
expectTypeOf<Context>()
expectTypeOf<NetlifyGlobal>()
expectTypeOf<Context>().toExtend<object>()
expectTypeOf<NetlifyGlobal>().toExtend<object>()
Comment on lines +11 to +12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turns out these existing vitest type assertions weren't doing anything

})

test('Does not export runtime code', () => {
Expand Down
9 changes: 9 additions & 0 deletions packages/types/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
typecheck: {
enabled: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the existing vitest type assertions in packages/types were also not doing anything because of this

},
},
})
Loading