[ci] format
This commit is contained in:
parent
7481ffda02
commit
6ce8ae261f
3 changed files with 100 additions and 79 deletions
|
@ -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',
|
||||||
|
|
|
@ -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,81 +35,107 @@ 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(
|
||||||
const { stdout } = setup([
|
(resolve, onStdout) => {
|
||||||
inputs.emptyDir,
|
const { stdout } = setup([
|
||||||
'--template', 'minimal',
|
inputs.emptyDir,
|
||||||
'--install', '0',
|
'--template',
|
||||||
'--git', '0'
|
'minimal',
|
||||||
]);
|
'--install',
|
||||||
stdout.on('data', (chunk) => {
|
'0',
|
||||||
onStdout(chunk);
|
'--git',
|
||||||
if (chunk.includes(PROMPT_MESSAGES.typescript)) {
|
'0',
|
||||||
resolve();
|
]);
|
||||||
}
|
stdout.on('data', (chunk) => {
|
||||||
});
|
onStdout(chunk);
|
||||||
}, () => lastStdout);
|
if (chunk.includes(PROMPT_MESSAGES.typescript)) {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
() => 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(
|
||||||
const { stdout } = setup([
|
(resolve, onStdout) => {
|
||||||
inputs.emptyDir,
|
const { stdout } = setup([
|
||||||
'--template', 'minimal',
|
inputs.emptyDir,
|
||||||
'--install', '0',
|
'--template',
|
||||||
'--git', '0',
|
'minimal',
|
||||||
'--typescript', 'base'
|
'--install',
|
||||||
]);
|
'0',
|
||||||
stdout.on('data', (chunk) => {
|
'--git',
|
||||||
onStdout(chunk);
|
'0',
|
||||||
if (chunk.includes(PROMPT_MESSAGES.typescriptSucceed)) {
|
'--typescript',
|
||||||
resolve();
|
'base',
|
||||||
}
|
]);
|
||||||
});
|
stdout.on('data', (chunk) => {
|
||||||
}, () => lastStdout);
|
onStdout(chunk);
|
||||||
|
if (chunk.includes(PROMPT_MESSAGES.typescriptSucceed)) {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
() => 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(
|
||||||
let wrote = false;
|
(resolve, onStdout) => {
|
||||||
const { stdout, stdin } = setup([
|
let wrote = false;
|
||||||
inputs.emptyDir,
|
const { stdout, stdin } = setup([
|
||||||
'--template', 'minimal',
|
inputs.emptyDir,
|
||||||
'--install', '0',
|
'--template',
|
||||||
'--git', '0'
|
'minimal',
|
||||||
]);
|
'--install',
|
||||||
stdout.on('data', (chunk) => {
|
'0',
|
||||||
onStdout(chunk);
|
'--git',
|
||||||
if (!wrote && chunk.includes(PROMPT_MESSAGES.typescript)) {
|
'0',
|
||||||
stdin.write('\x1B\x5B\x42\x0D');
|
]);
|
||||||
wrote = true;
|
stdout.on('data', (chunk) => {
|
||||||
}
|
onStdout(chunk);
|
||||||
if (chunk.includes(PROMPT_MESSAGES.typescriptSucceed)) {
|
if (!wrote && chunk.includes(PROMPT_MESSAGES.typescript)) {
|
||||||
const tsConfigJson = getTsConfig(inputs.emptyDir);
|
stdin.write('\x1B\x5B\x42\x0D');
|
||||||
expect(tsConfigJson).to.deep.equal({'extends': 'astro/tsconfigs/strict'});
|
wrote = true;
|
||||||
resolve();
|
}
|
||||||
}
|
if (chunk.includes(PROMPT_MESSAGES.typescriptSucceed)) {
|
||||||
});
|
const tsConfigJson = getTsConfig(inputs.emptyDir);
|
||||||
}, () => lastStdout);
|
expect(tsConfigJson).to.deep.equal({ extends: 'astro/tsconfigs/strict' });
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
() => 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(
|
||||||
const { stdout } = setup([
|
(resolve, onStdout) => {
|
||||||
inputs.emptyDir,
|
const { stdout } = setup([
|
||||||
'--template', 'cassidoo/shopify-react-astro',
|
inputs.emptyDir,
|
||||||
'--install', '0',
|
'--template',
|
||||||
'--git', '0',
|
'cassidoo/shopify-react-astro',
|
||||||
'--typescript', 'base'
|
'--install',
|
||||||
]);
|
'0',
|
||||||
stdout.on('data', (chunk) => {
|
'--git',
|
||||||
onStdout(chunk);
|
'0',
|
||||||
if (chunk.includes(PROMPT_MESSAGES.typescriptSucceed)) {
|
'--typescript',
|
||||||
const tsConfigJson = getTsConfig(inputs.emptyDir);
|
'base',
|
||||||
expect(tsConfigJson).to.deep.equal({'extends': 'astro/tsconfigs/base'});
|
]);
|
||||||
resolve();
|
stdout.on('data', (chunk) => {
|
||||||
}
|
onStdout(chunk);
|
||||||
});
|
if (chunk.includes(PROMPT_MESSAGES.typescriptSucceed)) {
|
||||||
}, () => lastStdout);
|
const tsConfigJson = getTsConfig(inputs.emptyDir);
|
||||||
|
expect(tsConfigJson).to.deep.equal({ extends: 'astro/tsconfigs/base' });
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
() => lastStdout
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,18 +8,17 @@ 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) => {
|
||||||
let lastStdout;
|
let lastStdout;
|
||||||
function onStdout (chunk) {
|
function onStdout(chunk) {
|
||||||
lastStdout = stripAnsi(chunk.toString()).trim() || lastStdout;
|
lastStdout = stripAnsi(chunk.toString()).trim() || lastStdout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +29,7 @@ export function promiseWithTimeout(testFn) {
|
||||||
clearTimeout(timeoutEvent);
|
clearTimeout(timeoutEvent);
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
testFn(resolver, onStdout);
|
testFn(resolver, onStdout);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -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 = []) {
|
||||||
|
|
Loading…
Reference in a new issue