|
1 | 1 | import { CheerioAPI, load } from 'cheerio'
|
2 | 2 | import { getLogger } from 'lambda-local'
|
3 | 3 | import { v4 } from 'uuid'
|
4 |
| -import { beforeAll, describe, expect, test, vi } from 'vitest' |
| 4 | +import { afterAll, beforeAll, describe, expect, test, vi } from 'vitest' |
5 | 5 | import { type FixtureTestContext } from '../utils/contexts.js'
|
6 | 6 | import { createFixture, loadSandboxedFunction, runPlugin } from '../utils/fixture.js'
|
7 | 7 | import { generateRandomObjectID, startMockBlobStore } from '../utils/helpers.js'
|
8 | 8 | import { InvokeFunctionResult } from '../utils/lambda-helpers.mjs'
|
9 | 9 | import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs'
|
| 10 | +import { afterTestCleanup } from '../test-setup.js' |
10 | 11 |
|
11 | 12 | function compareDates(
|
12 | 13 | $response1: CheerioAPI,
|
@@ -145,25 +146,33 @@ declare module 'vitest' {
|
145 | 146 | // Disable the verbose logging of the lambda-local runtime
|
146 | 147 | getLogger().level = 'alert'
|
147 | 148 |
|
148 |
| -let ctx: FixtureTestContext |
149 |
| -beforeAll(async () => { |
150 |
| - ctx = { |
151 |
| - deployID: generateRandomObjectID(), |
152 |
| - siteID: v4(), |
153 |
| - } as FixtureTestContext |
154 |
| - |
155 |
| - vi.stubEnv('SITE_ID', ctx.siteID) |
156 |
| - vi.stubEnv('DEPLOY_ID', ctx.deployID) |
157 |
| - vi.stubEnv('NETLIFY_PURGE_API_TOKEN', 'fake-token') |
158 |
| - await startMockBlobStore(ctx as FixtureTestContext) |
159 |
| - |
160 |
| - await createFixture('use-cache', ctx) |
161 |
| - await runPlugin(ctx) |
162 |
| -}) |
163 |
| - |
164 | 149 | // only supporting latest variant (https://github.com/vercel/next.js/pull/76687)
|
165 | 150 | // first released in v15.3.0-canary.13 so we should not run tests on older next versions
|
166 | 151 | describe.skipIf(!nextVersionSatisfies('>=15.3.0-canary.13'))('use cache', () => {
|
| 152 | + // note that in this test suite we are setting up test fixture once |
| 153 | + // because every test is using different path and also using sandboxed functions |
| 154 | + // so tests are not sharing context between them and this make test running |
| 155 | + // much more performant |
| 156 | + let ctx: FixtureTestContext |
| 157 | + beforeAll(async () => { |
| 158 | + ctx = { |
| 159 | + deployID: generateRandomObjectID(), |
| 160 | + siteID: v4(), |
| 161 | + } as FixtureTestContext |
| 162 | + |
| 163 | + vi.stubEnv('SITE_ID', ctx.siteID) |
| 164 | + vi.stubEnv('DEPLOY_ID', ctx.deployID) |
| 165 | + vi.stubEnv('NETLIFY_PURGE_API_TOKEN', 'fake-token') |
| 166 | + await startMockBlobStore(ctx as FixtureTestContext) |
| 167 | + |
| 168 | + await createFixture('use-cache', ctx) |
| 169 | + await runPlugin(ctx) |
| 170 | + }) |
| 171 | + |
| 172 | + afterAll(async () => { |
| 173 | + await afterTestCleanup(ctx) |
| 174 | + }) |
| 175 | + |
167 | 176 | describe('default (in-memory cache entries, shared tag manifests)', () => {
|
168 | 177 | for (const {
|
169 | 178 | expectedCachingBehaviorWhenUseCacheRegenerates,
|
|
0 commit comments