diff --git a/packages/sanity/package.json b/packages/sanity/package.json index 997e4bafccd..0d45c483062 100644 --- a/packages/sanity/package.json +++ b/packages/sanity/package.json @@ -272,6 +272,7 @@ "@types/configstore": "^5.0.1", "@types/connect-history-api-fallback": "^1.5.2", "@types/debug": "^4.1.12", + "@types/jsdom": "^20.0.0", "@types/lodash": "^4.14.149", "@types/log-symbols": "^2.0.0", "@types/node": "^18.19.8", diff --git a/packages/sanity/src/_internal/cli/server/__tests__/renderDocument.test.tsx b/packages/sanity/src/_internal/cli/server/__tests__/renderDocument.test.tsx index 5a5ef2f9231..6301278762d 100644 --- a/packages/sanity/src/_internal/cli/server/__tests__/renderDocument.test.tsx +++ b/packages/sanity/src/_internal/cli/server/__tests__/renderDocument.test.tsx @@ -1,7 +1,9 @@ import {describe, expect, it} from '@jest/globals' +import {JSDOM} from 'jsdom' import {renderToStaticMarkup} from 'react-dom/server' -import {_prefixUrlWithBasePath, addImportMapToHtml} from '../renderDocument' +import {TIMESTAMPED_IMPORTMAP_INJECTOR_SCRIPT} from '../constants' +import {_prefixUrlWithBasePath, addTimestampedImportMapScriptToHtml} from '../renderDocument' describe('_prefixUrlWithBasePath', () => { describe('when basePath is default value of "/"', () => { @@ -69,13 +71,69 @@ describe('_prefixUrlWithBasePath', () => { }) }) -describe('addImportMapToHtml', () => { +describe('addTimestampedImportMapScriptToHtml', () => { const importMap = { imports: { react: 'https://example.com/react', }, } + it('takes the import map from the `#__imports` script tag synchronously creates an importmap', () => { + const importMapWithSanityTimestamps = { + ...importMap, + imports: { + ...importMap.imports, + 'sanity': 'https://sanity-cdn.work/v1/modules/sanity/default/%5E3.40.0/t12345', + 'sanity/': 'https://sanity-cdn.work/v1/modules/sanity/default/%5E3.40.0/t12345/', + '@sanity/vision': + 'https://sanity-cdn.work/v1/modules/@sanity__vision/default/%5E3.40.0/t12345', + '@sanity/vision/': + 'https://sanity-cdn.work/v1/modules/@sanity__vision/default/%5E3.40.0/t12345/', + }, + } + + const input = ` +