Skip to content

Commit 78b2d4a

Browse files
committed
chore: convert intex test to TS
1 parent 6d8fbc3 commit 78b2d4a

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

test/index.spec.js renamed to test/index.spec.ts

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import execa from 'execa'
21
import { relative } from 'pathe'
32
import { getAllPageDependencies } from '../packages/runtime/src/templates/getPageResolver'
43

@@ -9,8 +8,8 @@ jest.mock('../packages/runtime/src/helpers/utils', () => {
98
}
109
})
1110

12-
const Chance = require('chance')
13-
const {
11+
import Chance from "chance"
12+
import {
1413
writeJSON,
1514
unlink,
1615
existsSync,
@@ -21,34 +20,36 @@ const {
2120
pathExists,
2221
writeFile,
2322
move,
24-
} = require('fs-extra')
25-
const path = require('path')
26-
const process = require('process')
27-
const os = require('os')
28-
const cpy = require('cpy')
29-
const { dir: getTmpDir } = require('tmp-promise')
30-
const { downloadFile } = require('../packages/runtime/src/templates/handlerUtils')
31-
const { getExtendedApiRouteConfigs } = require('../packages/runtime/src/helpers/functions')
32-
const nextRuntimeFactory = require('../packages/runtime/src')
23+
} from "fs-extra"
24+
import path from "path"
25+
import process from "process"
26+
import os from "os"
27+
import cpy from "cpy"
28+
import { dir as getTmpDir } from "tmp-promise"
29+
import { downloadFile } from "../packages/runtime/src/templates/handlerUtils"
30+
import { getExtendedApiRouteConfigs } from "../packages/runtime/src/helpers/functions"
31+
// @ts-expect-error - TODO: Convert runtime export to ES6
32+
import nextRuntimeFactory from "../packages/runtime/src"
3333
const nextRuntime = nextRuntimeFactory({})
34-
const { watchForMiddlewareChanges } = require('../packages/runtime/src/helpers/compiler')
35-
const { HANDLER_FUNCTION_NAME, ODB_FUNCTION_NAME, IMAGE_FUNCTION_NAME } = require('../packages/runtime/src/constants')
36-
const { join } = require('pathe')
37-
const {
34+
import { watchForMiddlewareChanges } from "../packages/runtime/src/helpers/compiler"
35+
import { HANDLER_FUNCTION_NAME, ODB_FUNCTION_NAME, IMAGE_FUNCTION_NAME } from "../packages/runtime/src/constants"
36+
import { join } from "pathe"
37+
import {
3838
matchMiddleware,
3939
stripLocale,
4040
matchesRedirect,
4141
matchesRewrite,
4242
patchNextFiles,
4343
unpatchNextFiles,
44-
} = require('../packages/runtime/src/helpers/files')
45-
const {
44+
} from "../packages/runtime/src/helpers/files"
45+
import {
4646
getRequiredServerFiles,
4747
updateRequiredServerFiles,
4848
generateCustomHeaders,
49-
} = require('../packages/runtime/src/helpers/config')
50-
const { dirname, resolve } = require('path')
51-
const { getProblematicUserRewrites } = require('../packages/runtime/src/helpers/verification')
49+
} from "../packages/runtime/src/helpers/config"
50+
import { dirname, resolve } from "path"
51+
import { getProblematicUserRewrites } from "../packages/runtime/src/helpers/verification"
52+
import type { NetlifyPluginOptions } from '@netlify/build'
5253

5354
const chance = new Chance()
5455
const FIXTURES_DIR = `${__dirname}/fixtures`
@@ -57,7 +58,7 @@ const constants = {
5758
INTERNAL_FUNCTIONS_SRC: '.netlify/functions-internal',
5859
PUBLISH_DIR: '.next',
5960
FUNCTIONS_DIST: '.netlify/functions',
60-
}
61+
} as unknown as NetlifyPluginOptions["constants"]
6162
const utils = {
6263
build: {
6364
failBuild(message) {
@@ -69,7 +70,7 @@ const utils = {
6970
save: jest.fn(),
7071
restore: jest.fn(),
7172
},
72-
}
73+
} as unknown as NetlifyPluginOptions["utils"]
7374

7475
const normalizeChunkNames = (source) => source.replaceAll(/\/chunks\/\d+\.js/g, '/chunks/CHUNK_ID.js')
7576

@@ -174,12 +175,12 @@ const useFixture = async function (fixtureName) {
174175
await cpy('**', process.cwd(), { cwd: fixtureDir, parents: true, overwrite: true, dot: true })
175176
}
176177

177-
const netlifyConfig = { build: { command: 'npm run build' }, functions: {}, redirects: [], headers: [] }
178+
const netlifyConfig = { build: { command: 'npm run build' }, functions: {}, redirects: [], headers: [] } as NetlifyPluginOptions["netlifyConfig"]
178179
const defaultArgs = {
179180
netlifyConfig,
180181
utils,
181182
constants,
182-
}
183+
} as NetlifyPluginOptions
183184

184185
let restoreCwd
185186
let cleanup

0 commit comments

Comments
 (0)