Skip to content

Commit

Permalink
Update tests to use new import maps.
Browse files Browse the repository at this point in the history
  • Loading branch information
carloskelly13 committed Nov 18, 2023
1 parent 314136e commit 8d83c2c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
14 changes: 4 additions & 10 deletions packages/create-spectacle/src/cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import path from 'node:path';
import { exec } from 'node:child_process';
import fs from 'node:fs/promises';
import { generateImportMap } from './generators/one-page';
import exp from 'constants';

const CLI_PATH = path.resolve(__dirname, '../bin/cli.js');
const TMP_PATH = path.resolve(__dirname, '../tmp');
Expand Down Expand Up @@ -214,16 +216,8 @@ describe('create-spectacle', () => {
.readFile(HTML_PATH, 'utf8')
.then((buffer) => buffer.toString());

// Should have deps
const deps = [
'https://unpkg.com/[email protected]/umd/react.production.min.js',
'https://unpkg.com/[email protected]/umd/react-dom.production.min.js',
'https://unpkg.com/[email protected]/umd/react-is.production.min.js',
'https://unpkg.com/[email protected]/prop-types.min.js',
'https://unpkg.com/spectacle@^9/dist/spectacle.min.js'
];
deps.forEach((dep) => {
expect(contents).toContain(`<script src="${dep}"></script>`);
Array.from((await generateImportMap()).entries()).forEach(([pkg, url]) => {
expect(contents).toContain(`"${pkg}": "${url}"`);
});
});
});
Expand Down
7 changes: 6 additions & 1 deletion packages/create-spectacle/src/generators/one-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const spectaclePackage = require(`${SPECTACLE_PATH}/package.json`);
const REACT_VERSION = spectaclePackage.devDependencies.react.replace('^', '');
const ESM_SH_VERSION = 'v121';

export const createOnePage = async (name: string, lang: string) => {
export const generateImportMap = async () => {
const importMap = new Map<string, string>();
const {
dependencies,
Expand All @@ -27,6 +27,11 @@ export const createOnePage = async (name: string, lang: string) => {
handlePackageExceptions(pkg, version, importMap);
}

return importMap;
};

export const createOnePage = async (name: string, lang: string) => {
const importMap = await generateImportMap();
return onePageTemplate({ importMap, name, lang });
};

Expand Down

0 comments on commit 8d83c2c

Please sign in to comment.