Skip to content

Commit

Permalink
test: Fixing 'create' test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian committed Jul 8, 2022
1 parent 4683a72 commit 29fd1aa
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
11 changes: 7 additions & 4 deletions packages/cli/tests/lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const { join } = require('path');
const { mkdir, symlink, readFile, writeFile } = require('fs').promises;
const cmd = require('../../lib/commands');
const { build: buildCmd, watch: watchCmd } = require('../../lib/commands');
const {
create: createCmd,
} = require('../../../create-cli/src/commands/create');
const { tmpDir } = require('./output');
const { disableOptimizeConfig, disableOptimize } = require('./utils');

Expand Down Expand Up @@ -44,7 +47,7 @@ exports.create = async function (template, name) {
let dest = await tmpDir();
name = name || `test-${template}`;

await cmd.create(template, dest, { name, cwd: '.' });
await createCmd(template, dest, { name, cwd: '.' });

return dest;
};
Expand All @@ -55,7 +58,7 @@ const build = (exports.build = async function (cwd, options) {
await linkPackage('preact-render-to-string', root, cwd);

let opts = Object.assign({}, { cwd }, argv, options);
return await cmd.build(opts.src, opts);
return await buildCmd(opts.src, opts);
});

exports.buildFast = async function (cwd, options) {
Expand All @@ -68,5 +71,5 @@ exports.watch = function (cwd, port, host = '127.0.0.1') {
delete args.dest;
delete args['inline-css'];
let opts = Object.assign({ cwd, host, port, https: false }, args);
return cmd.watch(argv.src, opts);
return watchCmd(argv.src, opts);
};
4 changes: 4 additions & 0 deletions packages/create-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"repository": "preactjs/preact-cli",
"main": "src/index.js",
"bin": "src/index.js",
"scripts": {
"pretest": "rimraf ../cli/tests/output",
"test": "jest"
},
"engines": {
"node": ">=14"
},
Expand Down
9 changes: 9 additions & 0 deletions packages/create-cli/tests/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"env": {
"jest": true,
"jasmine": true
},
"globals": {
"jasmine": true
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { readFile } = require('fs').promises;
const { readFile } = require('fs/promises');
const { relative, resolve } = require('path');
const { create } = require('./lib/cli');
const { expand } = require('./lib/utils');
const { create } = require('../../cli/tests/lib/cli');
const { expand } = require('../../cli/tests/lib/utils');
const snapshots = require('./images/create');

describe('preact create', () => {
Expand Down Expand Up @@ -32,12 +32,4 @@ describe('preact create', () => {

expect(template.includes('apple-touch-icon')).toEqual(true);
});

it('should fail given an invalid name', async () => {
// @ts-ignore
const exit = jest.spyOn(process, 'exit').mockImplementation(() => {});
await create('simple', '*()@!#!$-Invalid-Name');

expect(exit).toHaveBeenCalledWith(1);
});
});
File renamed without changes.

0 comments on commit 29fd1aa

Please sign in to comment.