-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ease Nuxt 4 update by removing
app/
prefix from Prismic files
- Loading branch information
Showing
12 changed files
with
252 additions
and
50 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
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
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
File renamed without changes.
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
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
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,138 @@ | ||
import { it, expect, vi, afterEach } from 'vitest' | ||
import { vol } from 'memfs' | ||
|
||
import { addTemplate } from '@nuxt/kit' | ||
|
||
import prismicModule from '../src/module' | ||
|
||
import { mockModule } from './__testutils__/mockModule' | ||
|
||
const mockedPrismicModule = mockModule(prismicModule) | ||
|
||
vi.mock('../src/lib/logger.ts', () => ({ | ||
logger: { info: vi.fn(), warn: vi.fn() }, | ||
})) | ||
vi.mock('@nuxt/kit', async () => { | ||
const { mockedNuxtKit } = await vi.importActual<typeof import('./__testutils__/mockedNuxtKit')>('./__testutils__/mockedNuxtKit') | ||
|
||
return mockedNuxtKit({ nuxt4: true }) | ||
}) | ||
|
||
afterEach(() => { | ||
vi.clearAllMocks() | ||
}) | ||
|
||
it('proxies nothing if user files are not available', () => { | ||
mockedPrismicModule({ endpoint: 'qwerty' }) | ||
|
||
expect(addTemplate).toHaveBeenCalledTimes(3) | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
expect(vi.mocked(addTemplate).mock.calls.flat().map((options: any) => [options.filename, options.getContents()])).toMatchInlineSnapshot(` | ||
[ | ||
[ | ||
"prismic/proxy/client.ts", | ||
"export default undefined", | ||
], | ||
[ | ||
"prismic/proxy/linkResolver.ts", | ||
"export default undefined", | ||
], | ||
[ | ||
"prismic/proxy/richTextSerializer.ts", | ||
"export default undefined", | ||
], | ||
] | ||
`) | ||
}) | ||
|
||
it('proxies user files from default location', () => { | ||
vol.fromJSON({ | ||
'/tmp/nuxt/app/prismic/client.ts': '', | ||
'/tmp/nuxt/app/prismic/linkResolver.ts': '', | ||
'/tmp/nuxt/app/prismic/richTextSerializer.ts': '', | ||
}) | ||
|
||
mockedPrismicModule({ endpoint: 'qwerty' }) | ||
|
||
expect(addTemplate).toHaveBeenCalledTimes(3) | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
expect(vi.mocked(addTemplate).mock.calls.flat().map((options: any) => [options.filename, options.getContents()])).toMatchInlineSnapshot(` | ||
[ | ||
[ | ||
"prismic/proxy/client.ts", | ||
"export { default } from '~/prismic/client'", | ||
], | ||
[ | ||
"prismic/proxy/linkResolver.ts", | ||
"export { default } from '~/prismic/linkResolver'", | ||
], | ||
[ | ||
"prismic/proxy/richTextSerializer.ts", | ||
"export { default } from '~/prismic/richTextSerializer'", | ||
], | ||
] | ||
`) | ||
}) | ||
|
||
it('proxies user files from default location (Nuxt 4)', () => { | ||
vol.fromJSON({ | ||
'/tmp/nuxt/app/prismic/client.ts': '', | ||
'/tmp/nuxt/app/prismic/linkResolver.ts': '', | ||
'/tmp/nuxt/app/prismic/richTextSerializer.ts': '', | ||
}) | ||
|
||
mockedPrismicModule({ endpoint: 'qwerty' }) | ||
|
||
expect(addTemplate).toHaveBeenCalledTimes(3) | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
expect(vi.mocked(addTemplate).mock.calls.flat().map((options: any) => [options.filename, options.getContents()])).toMatchInlineSnapshot(` | ||
[ | ||
[ | ||
"prismic/proxy/client.ts", | ||
"export { default } from '~/prismic/client'", | ||
], | ||
[ | ||
"prismic/proxy/linkResolver.ts", | ||
"export { default } from '~/prismic/linkResolver'", | ||
], | ||
[ | ||
"prismic/proxy/richTextSerializer.ts", | ||
"export { default } from '~/prismic/richTextSerializer'", | ||
], | ||
] | ||
`) | ||
}) | ||
|
||
it('proxies user files from provided location', () => { | ||
vol.fromJSON({ | ||
'/tmp/nuxt/app/custom/client.ts': '', | ||
'/tmp/nuxt/app/custom/linkResolver.ts': '', | ||
'/tmp/nuxt/app/custom/richTextSerializer.ts': '', | ||
}) | ||
|
||
mockedPrismicModule({ | ||
endpoint: 'qwerty', | ||
client: '~/custom/client', | ||
linkResolver: '~/custom/linkResolver', | ||
richTextSerializer: '~/custom/richTextSerializer', | ||
}) | ||
|
||
expect(addTemplate).toHaveBeenCalledTimes(3) | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
expect(vi.mocked(addTemplate).mock.calls.flat().map((options: any) => [options.filename, options.getContents()])).toMatchInlineSnapshot(` | ||
[ | ||
[ | ||
"prismic/proxy/client.ts", | ||
"export { default } from '~/custom/client'", | ||
], | ||
[ | ||
"prismic/proxy/linkResolver.ts", | ||
"export { default } from '~/custom/linkResolver'", | ||
], | ||
[ | ||
"prismic/proxy/richTextSerializer.ts", | ||
"export { default } from '~/custom/richTextSerializer'", | ||
], | ||
] | ||
`) | ||
}) |
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.