-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: attempt to reproduce jest issue (#134)
- Loading branch information
Showing
11 changed files
with
1,172 additions
and
408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { GET } from './route'; | ||
|
||
describe('app API edge-no-context route', () => { | ||
const log = jest.spyOn(console, 'log').mockImplementation(() => void 0); | ||
|
||
beforeEach(() => jest.clearAllMocks()); | ||
|
||
it('tracks event', async () => { | ||
const response = await GET(new Request(new URL('/', 'http://localhost'))); | ||
expect(response.status).toBe(200); | ||
expect(log).toHaveBeenCalledTimes(1); | ||
expect(log).toHaveBeenCalledWith( | ||
'[Vercel Web Analytics] Track "Edge Event" with data {"data":"edge","router":"app","manual":true}' | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { GET } from './route'; | ||
|
||
describe('app API edge route', () => { | ||
const log = jest.spyOn(console, 'log').mockImplementation(() => void 0); | ||
|
||
beforeEach(() => jest.clearAllMocks()); | ||
|
||
it('tracks event', async () => { | ||
const response = await GET(); | ||
expect(response.status).toBe(200); | ||
expect(log).toHaveBeenCalledTimes(1); | ||
expect(log).toHaveBeenCalledWith( | ||
'[Vercel Web Analytics] Track "Edge Event" with data {"data":"edge","router":"app"}' | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { GET } from './route'; | ||
|
||
describe('app API serverless route', () => { | ||
const log = jest.spyOn(console, 'log').mockImplementation(() => void 0); | ||
|
||
beforeEach(() => jest.clearAllMocks()); | ||
|
||
it('tracks event', async () => { | ||
const response = await GET(); | ||
expect(response.status).toBe(200); | ||
expect(log).toHaveBeenCalledTimes(1); | ||
expect(log).toHaveBeenCalledWith( | ||
'[Vercel Web Analytics] Track "Serverless Event" with data {"data":"serverless","router":"app"}' | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import '@testing-library/jest-dom'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { Config } from 'jest'; | ||
import nextJest from 'next/jest.js'; | ||
|
||
const createJestConfig = nextJest({ | ||
dir: './', | ||
}); | ||
|
||
const config: Config = { | ||
coverageProvider: 'v8', | ||
testRegex: '\\/.+\\.test\\.tsx?$', | ||
setupFilesAfterEnv: ['<rootDir>/jest-setup.ts'], | ||
transform: { | ||
'^.+\\.(t|j)sx?$': '@swc/jest', | ||
}, | ||
}; | ||
|
||
export default createJestConfig(config); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { NextRequest } from 'next/server'; | ||
import GET from './test'; | ||
|
||
describe('pages API edge route', () => { | ||
const log = jest.spyOn(console, 'log').mockImplementation(() => void 0); | ||
|
||
beforeEach(() => jest.clearAllMocks()); | ||
|
||
it('tracks event', async () => { | ||
const request = new NextRequest(new URL('/', 'http://localhost')); | ||
// @ts-expect-error -- we should pass a NextFetchEvent instead an empty object, but it's not used. | ||
const response = await GET(request, {}); | ||
expect(response.status).toBe(200); | ||
expect(log).toHaveBeenCalledTimes(1); | ||
expect(log).toHaveBeenCalledWith( | ||
'[Vercel Web Analytics] Track "Pages Api Route" with data {"runtime":"edge","router":"pages"}' | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.