Skip to content

Commit

Permalink
test: Update 'create' test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian committed Jul 16, 2022
1 parent 3c2f069 commit 2dd3636
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
11 changes: 5 additions & 6 deletions packages/create-cli/src/commands/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ exports.create = async function create(repo, dest, argv) {

if (!repo.includes('/')) {
repo = `preactjs-templates/${repo}`;

// TODO: Remove this after updating all templates
if (repo.endsWith('default') || repo.endsWith('typescript')) {
repo += '#main';
}
}

await mkdir(resolve(cwd, dest), { recursive: true });
Expand Down Expand Up @@ -109,12 +114,6 @@ exports.create = async function create(repo, dest, argv) {
await copyTemplateFile(serviceWorkerSrc, serviceWorkerDest, argv.force);
}

// TODO: Remove when templates are updated
const packagePath = join(target, 'package.json');
let packageFile = JSON.parse(await readFile(packagePath, 'utf-8'));
packageFile.name = 'foo';
await writeFile(packagePath, JSON.stringify(packageFile, null, 2));

if (argv.install) {
spinner.text = 'installing dependencies...';
spinner.stopAndPersist();
Expand Down
13 changes: 2 additions & 11 deletions packages/create-cli/tests/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { expand } = require('../../cli/tests/lib/utils');
const snapshots = require('./images/create');

describe('preact create', () => {
it(`scaffolds the 'default' official template`, async () => {
it('scaffolds the `default` official template', async () => {
let dir = await create('default');

let output = await expand(dir).then(arr => {
Expand All @@ -15,21 +15,12 @@ describe('preact create', () => {
expect(output.sort()).toEqual(snapshots.default);
});

it(`should use template.html from the github repo`, async () => {
it('should use template.html from the repo if one exists', async () => {
let dir = await create('netlify');

const templateFilePath = resolve(__dirname, dir, 'src', 'template.html');
const template = await readFile(templateFilePath, 'utf8');

expect(template.includes('twitter:card')).toEqual(true);
});

it(`should have 'apple-touch-icon' meta tag`, async () => {
let dir = await create('simple');

const templateFilePath = resolve(__dirname, dir, 'src', 'template.html');
const template = await readFile(templateFilePath, 'utf8');

expect(template.includes('apple-touch-icon')).toEqual(true);
});
});
6 changes: 3 additions & 3 deletions packages/create-cli/tests/images/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ exports.default = [
'src/assets/icons/mstile-150x150.png',
'src/components/app.js',
'src/components/header/index.js',
'src/components/header/style.css',
'src/components/header/style.module.css',
'src/index.js',
'src/manifest.json',
'src/routes/home/index.js',
'src/routes/home/style.css',
'src/routes/home/style.module.css',
'src/routes/profile/index.js',
'src/routes/profile/style.css',
'src/routes/profile/style.module.css',
'src/style/index.css',
'src/sw.js',
'src/template.html',
Expand Down

0 comments on commit 2dd3636

Please sign in to comment.