[ci] format

This commit is contained in:
matthewp 2022-09-22 18:39:14 +00:00 committed by fredkbot
parent 7481ffda02
commit 6ce8ae261f
3 changed files with 100 additions and 79 deletions

View file

@ -1,8 +1,6 @@
import path from 'path'; import path from 'path';
import { promises, existsSync } from 'fs'; import { promises, existsSync } from 'fs';
import { import { PROMPT_MESSAGES, testDir, setup, promiseWithTimeout, timeout } from './utils.js';
PROMPT_MESSAGES, testDir, setup, promiseWithTimeout, timeout
} from './utils.js';
const inputs = { const inputs = {
nonEmptyDir: './fixtures/select-directory/nonempty-dir', nonEmptyDir: './fixtures/select-directory/nonempty-dir',

View file

@ -2,9 +2,7 @@ import { expect } from 'chai';
import { deleteSync } from 'del'; import { deleteSync } from 'del';
import { existsSync, mkdirSync, readdirSync, readFileSync } from 'fs'; import { existsSync, mkdirSync, readdirSync, readFileSync } from 'fs';
import path from 'path'; import path from 'path';
import { import { PROMPT_MESSAGES, testDir, setup, promiseWithTimeout, timeout } from './utils.js';
PROMPT_MESSAGES, testDir, setup, promiseWithTimeout, timeout
} from './utils.js';
const inputs = { const inputs = {
emptyDir: './fixtures/select-typescript/empty-dir', emptyDir: './fixtures/select-typescript/empty-dir',
@ -37,12 +35,16 @@ describe('[create-astro] select typescript', function () {
afterEach(ensureEmptyDir); afterEach(ensureEmptyDir);
it('should prompt for typescript when none is provided', async function () { it('should prompt for typescript when none is provided', async function () {
return promiseWithTimeout((resolve, onStdout) => { return promiseWithTimeout(
(resolve, onStdout) => {
const { stdout } = setup([ const { stdout } = setup([
inputs.emptyDir, inputs.emptyDir,
'--template', 'minimal', '--template',
'--install', '0', 'minimal',
'--git', '0' '--install',
'0',
'--git',
'0',
]); ]);
stdout.on('data', (chunk) => { stdout.on('data', (chunk) => {
onStdout(chunk); onStdout(chunk);
@ -50,17 +52,24 @@ describe('[create-astro] select typescript', function () {
resolve(); resolve();
} }
}); });
}, () => lastStdout); },
() => lastStdout
);
}); });
it('should not prompt for typescript when provided', async function () { it('should not prompt for typescript when provided', async function () {
return promiseWithTimeout((resolve, onStdout) => { return promiseWithTimeout(
(resolve, onStdout) => {
const { stdout } = setup([ const { stdout } = setup([
inputs.emptyDir, inputs.emptyDir,
'--template', 'minimal', '--template',
'--install', '0', 'minimal',
'--git', '0', '--install',
'--typescript', 'base' '0',
'--git',
'0',
'--typescript',
'base',
]); ]);
stdout.on('data', (chunk) => { stdout.on('data', (chunk) => {
onStdout(chunk); onStdout(chunk);
@ -68,17 +77,23 @@ describe('[create-astro] select typescript', function () {
resolve(); resolve();
} }
}); });
}, () => lastStdout); },
() => lastStdout
);
}); });
it('should use "strict" config when specified', async function () { it('should use "strict" config when specified', async function () {
return promiseWithTimeout((resolve, onStdout) => { return promiseWithTimeout(
(resolve, onStdout) => {
let wrote = false; let wrote = false;
const { stdout, stdin } = setup([ const { stdout, stdin } = setup([
inputs.emptyDir, inputs.emptyDir,
'--template', 'minimal', '--template',
'--install', '0', 'minimal',
'--git', '0' '--install',
'0',
'--git',
'0',
]); ]);
stdout.on('data', (chunk) => { stdout.on('data', (chunk) => {
onStdout(chunk); onStdout(chunk);
@ -88,30 +103,39 @@ describe('[create-astro] select typescript', function () {
} }
if (chunk.includes(PROMPT_MESSAGES.typescriptSucceed)) { if (chunk.includes(PROMPT_MESSAGES.typescriptSucceed)) {
const tsConfigJson = getTsConfig(inputs.emptyDir); const tsConfigJson = getTsConfig(inputs.emptyDir);
expect(tsConfigJson).to.deep.equal({'extends': 'astro/tsconfigs/strict'}); expect(tsConfigJson).to.deep.equal({ extends: 'astro/tsconfigs/strict' });
resolve(); resolve();
} }
}); });
}, () => lastStdout); },
() => lastStdout
);
}); });
it('should create tsconfig.json when missing', async function () { it('should create tsconfig.json when missing', async function () {
return promiseWithTimeout((resolve, onStdout) => { return promiseWithTimeout(
(resolve, onStdout) => {
const { stdout } = setup([ const { stdout } = setup([
inputs.emptyDir, inputs.emptyDir,
'--template', 'cassidoo/shopify-react-astro', '--template',
'--install', '0', 'cassidoo/shopify-react-astro',
'--git', '0', '--install',
'--typescript', 'base' '0',
'--git',
'0',
'--typescript',
'base',
]); ]);
stdout.on('data', (chunk) => { stdout.on('data', (chunk) => {
onStdout(chunk); onStdout(chunk);
if (chunk.includes(PROMPT_MESSAGES.typescriptSucceed)) { if (chunk.includes(PROMPT_MESSAGES.typescriptSucceed)) {
const tsConfigJson = getTsConfig(inputs.emptyDir); const tsConfigJson = getTsConfig(inputs.emptyDir);
expect(tsConfigJson).to.deep.equal({'extends': 'astro/tsconfigs/base'}); expect(tsConfigJson).to.deep.equal({ extends: 'astro/tsconfigs/base' });
resolve(); resolve();
} }
}); });
}, () => lastStdout); },
() => lastStdout
);
}); });
}); });

View file

@ -8,13 +8,12 @@ export const testDir = dirname(__filename);
export const timeout = 5000; export const timeout = 5000;
const timeoutError = function (details) { const timeoutError = function (details) {
let errorMsg = let errorMsg = 'Timed out waiting for create-astro to respond with expected output.';
'Timed out waiting for create-astro to respond with expected output.';
if (details) { if (details) {
errorMsg += '\nLast output: "' + details + '"'; errorMsg += '\nLast output: "' + details + '"';
} }
return new Error(errorMsg); return new Error(errorMsg);
} };
export function promiseWithTimeout(testFn) { export function promiseWithTimeout(testFn) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -39,7 +38,7 @@ export const PROMPT_MESSAGES = {
directory: 'Where would you like to create your new project?', directory: 'Where would you like to create your new project?',
template: 'Which template would you like to use?', template: 'Which template would you like to use?',
typescript: 'How would you like to setup TypeScript?', typescript: 'How would you like to setup TypeScript?',
typescriptSucceed: 'Next steps' typescriptSucceed: 'Next steps',
}; };
export function setup(args = []) { export function setup(args = []) {