Skip to content

Commit bcce91f

Browse files
committed
chore: more fixes
1 parent eb54c75 commit bcce91f

16 files changed

+202
-165
lines changed

.eslintrc.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,22 @@ module.exports = {
6060
},
6161
},
6262
{
63-
files: ['test/**'],
63+
files: ['test/**', 'packages/**/test/**'],
6464
plugins: ['jest'],
6565
extends: ['plugin:jest/recommended'],
6666
rules: {
6767
// Disable global rules
68-
'max-nested-callbacks': 0,
68+
'max-nested-callbacks': 'off',
6969
'@typescript-eslint/no-empty-function': 0,
7070
'max-lines-per-function': 0,
7171
'unicorn/no-empty-file': 0,
72+
'prefer-destructuring': 0,
73+
'@typescript-eslint/no-unused-vars': 0,
74+
'unicorn/no-await-expression-member': 0,
7275
// esling-plugin-jest specific rules
7376
'jest/consistent-test-it': ['error', { fn: 'it', withinDescribe: 'it' }],
77+
'jest/no-disabled-tests': 0,
78+
'jest/no-conditional-expect': 0,
7479
},
7580
},
7681
],

package-lock.json

Lines changed: 60 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"eslint-plugin-promise": "^6.0.0",
7272
"eslint-plugin-unicorn": "^43.0.2",
7373
"execa": "^5.1.1",
74+
"fs-extra": "^11.1.1",
7475
"husky": "^7.0.4",
7576
"jest": "^27.0.0",
7677
"jest-extended": "^3.2.0",

packages/next/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"devDependencies": {
1010
"@netlify/edge-functions": "^2.0.0",
1111
"@types/node": "^17.0.25",
12+
"chance": "^1.1.11",
1213
"next": "^13.3.0",
1314
"npm-run-all": "^4.1.5",
1415
"typescript": "^4.6.3"

packages/next/test/request.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Chance from 'chance'
22
import { NextURL } from 'next/dist/server/web/next-url'
33
import { RequestCookies } from 'next/dist/server/web/spec-extension/cookies'
44
import { NextRequest } from 'next/server'
5+
56
import { MiddlewareRequest } from '../src/middleware/request'
67

78
const chance = new Chance()
@@ -75,19 +76,19 @@ describe('MiddlewareRequest', () => {
7576

7677
it('throws an error when MiddlewareRequest is run outside of edge environment', () => {
7778
delete globalThis.Deno
78-
expect(() => new MiddlewareRequest(nextRequest)).toThrowError(
79+
expect(() => new MiddlewareRequest(nextRequest)).toThrow(
7980
'MiddlewareRequest only works in a Netlify Edge Function environment',
8081
)
8182
})
8283

8384
it('throws an error when x-nf-request-id header is missing', () => {
8485
nextRequest.headers.delete('x-nf-request-id')
85-
expect(() => new MiddlewareRequest(nextRequest)).toThrowError('Missing x-nf-request-id header')
86+
expect(() => new MiddlewareRequest(nextRequest)).toThrow('Missing x-nf-request-id header')
8687
})
8788

8889
it('throws an error when request context is missing', () => {
8990
globalThis.NFRequestContextMap.delete(requestId)
90-
expect(() => new MiddlewareRequest(nextRequest)).toThrowError(
91+
expect(() => new MiddlewareRequest(nextRequest)).toThrow(
9192
`Could not find request context for request id ${requestId}`,
9293
)
9394
})

test/helpers/analysis.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { extractConfigFromFile } from '../../packages/runtime/src/helpers/analysis'
21
import { resolve } from 'pathe'
32

3+
import { extractConfigFromFile } from '../../packages/runtime/src/helpers/analysis'
4+
45
describe('static source analysis', () => {
56
beforeEach(() => {
67
// Spy on console.error

test/helpers/config.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { generateCustomHeaders, NextConfig } from '../../packages/runtime/src/helpers/config'
21
import type { NetlifyPluginOptions } from '@netlify/build'
32

3+
import { generateCustomHeaders, NextConfig } from '../../packages/runtime/src/helpers/config'
4+
45
const netlifyConfig = {
56
build: { command: 'npm run build' },
67
functions: {},

test/helpers/edge.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { generateRscDataEdgeManifest } from '../../packages/runtime/src/helpers/edge'
21
import type { PrerenderManifest } from 'next/dist/build'
32

3+
import { generateRscDataEdgeManifest } from '../../packages/runtime/src/helpers/edge'
4+
45
jest.mock('../../packages/runtime/src/helpers/functionsMetaData', () => {
56
const { NEXT_PLUGIN_NAME } = require('../../packages/runtime/src/constants')
67
return {

test/helpers/files.spec.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import path, { dirname } from 'path'
2+
3+
import { readFileSync, copy, ensureDir } from 'fs-extra'
4+
import { resolve , join } from 'pathe'
5+
16
import {
27
matchMiddleware,
38
stripLocale,
@@ -8,11 +13,6 @@ import {
813
getDependenciesOfFile,
914
getSourceFileForPage,
1015
} from '../../packages/runtime/src/helpers/files'
11-
import { readFileSync, copy, ensureDir } from 'fs-extra'
12-
import path from 'path'
13-
import { dirname } from 'path'
14-
import { resolve } from 'pathe'
15-
import { join } from 'pathe'
1616
import { Rewrites } from '../../packages/runtime/src/helpers/types'
1717
import { describeCwdTmpDir, moveNextDist } from '../test-utils'
1818

@@ -59,7 +59,7 @@ const REWRITES: Rewrites = [
5959
]
6060

6161
describe('files utility functions', () => {
62-
test('middleware tester matches correct paths', () => {
62+
it('middleware tester matches correct paths', () => {
6363
const middleware = ['middle', 'sub/directory']
6464
const paths = [
6565
'middle.html',
@@ -76,7 +76,7 @@ describe('files utility functions', () => {
7676
}
7777
})
7878

79-
test('middleware tester does not match incorrect paths', () => {
79+
it('middleware tester does not match incorrect paths', () => {
8080
const middleware = ['middle', 'sub/directory']
8181
const paths = [
8282
'middl',
@@ -93,7 +93,7 @@ describe('files utility functions', () => {
9393
}
9494
})
9595

96-
test('middleware tester matches root middleware', () => {
96+
it('middleware tester matches root middleware', () => {
9797
const middleware = ['']
9898
const paths = [
9999
'middl',
@@ -110,7 +110,7 @@ describe('files utility functions', () => {
110110
}
111111
})
112112

113-
test('middleware tester matches root middleware', () => {
113+
it('middleware tester matches root middleware', () => {
114114
const paths = [
115115
'middl',
116116
'',
@@ -126,7 +126,7 @@ describe('files utility functions', () => {
126126
}
127127
})
128128

129-
test('stripLocale correctly strips matching locales', () => {
129+
it('stripLocale correctly strips matching locales', () => {
130130
const locales = ['en', 'fr', 'en-GB']
131131
const paths = [
132132
['en/file.html', 'file.html'],
@@ -140,29 +140,29 @@ describe('files utility functions', () => {
140140
}
141141
})
142142

143-
test('stripLocale does not touch non-matching matching locales', () => {
143+
it('stripLocale does not touch non-matching matching locales', () => {
144144
const locales = ['en', 'fr', 'en-GB']
145145
const paths = ['de/file.html', 'enfile.html', 'en-US/file.html']
146146
for (const path of paths) {
147147
expect(stripLocale(path, locales)).toEqual(path)
148148
}
149149
})
150150

151-
test('matchesRedirect correctly matches paths with locales', () => {
151+
it('matchesRedirect correctly matches paths with locales', () => {
152152
const paths = ['en/redirectme.html', 'en/redirectme.json', 'fr/redirectme.html', 'fr/redirectme.json']
153153
paths.forEach((path) => {
154154
expect(matchesRedirect(path, REDIRECTS)).toBeTruthy()
155155
})
156156
})
157157

158-
test("matchesRedirect doesn't match paths with invalid locales", () => {
158+
it("matchesRedirect doesn't match paths with invalid locales", () => {
159159
const paths = ['dk/redirectme.html', 'dk/redirectme.json', 'gr/redirectme.html', 'gr/redirectme.json']
160160
paths.forEach((path) => {
161161
expect(matchesRedirect(path, REDIRECTS)).toBeFalsy()
162162
})
163163
})
164164

165-
test("matchesRedirect doesn't match internal redirects", () => {
165+
it("matchesRedirect doesn't match internal redirects", () => {
166166
const paths = ['en/notrailingslash']
167167
paths.forEach((path) => {
168168
expect(matchesRedirect(path, REDIRECTS)).toBeFalsy()

test/helpers/functionsMetaData.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { readJSON } from 'fs-extra'
22
import mock from 'mock-fs'
33
import { join } from 'pathe'
4+
45
import { NEXT_PLUGIN_NAME } from '../../packages/runtime/src/constants'
56
import { writeFunctionConfiguration } from '../../packages/runtime/src/helpers/functionsMetaData'
67

test/helpers/matchers.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { makeLocaleOptional, stripLookahead } from '../../packages/runtime/src/helpers/matchers'
21
import { getEdgeFunctionPatternForPage } from '../../packages/runtime/src/helpers/edge'
2+
import { makeLocaleOptional, stripLookahead } from '../../packages/runtime/src/helpers/matchers'
3+
34
const makeDataPath = (path: string) => `/_next/data/build-id${path === '/' ? '/index' : path}.json`
45

56
function checkPath(path: string, regex: string) {

test/helpers/utils.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Chance from 'chance'
22
import { ExperimentalConfig } from 'next/dist/server/config-shared'
3+
34
import {
45
getCustomImageResponseHeaders,
56
getRemotePatterns,

0 commit comments

Comments
 (0)