[ci] format
This commit is contained in:
parent
84939b2ff2
commit
84b863df6a
1 changed files with 54 additions and 52 deletions
|
@ -1,12 +1,14 @@
|
||||||
import { execa} from 'execa';
|
import { execa } from 'execa';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import { dirname, resolve } from 'path';
|
import { dirname, resolve } from 'path';
|
||||||
import {promises, existsSync} from 'fs'
|
import { promises, existsSync } from 'fs';
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = dirname(__filename);
|
const __dirname = dirname(__filename);
|
||||||
|
|
||||||
const createAstroError = new Error('Timed out waiting for create-astro to respond with expected output.')
|
const createAstroError = new Error(
|
||||||
|
'Timed out waiting for create-astro to respond with expected output.'
|
||||||
|
);
|
||||||
const timeout = 5000;
|
const timeout = 5000;
|
||||||
|
|
||||||
const instructions = {
|
const instructions = {
|
||||||
|
@ -29,74 +31,74 @@ function promiseWithTimeout(testFn) {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
testFn(resolver);
|
testFn(resolver);
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setup(args = []) {
|
function setup(args = []) {
|
||||||
const {stdout, stdin} = execa('../create-astro.mjs', args, { cwd: __dirname })
|
const { stdout, stdin } = execa('../create-astro.mjs', args, { cwd: __dirname });
|
||||||
return {
|
return {
|
||||||
stdin,
|
stdin,
|
||||||
stdout,
|
stdout,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('[create-astro] select directory', function() {
|
describe('[create-astro] select directory', function () {
|
||||||
this.timeout(timeout);
|
this.timeout(timeout);
|
||||||
it ('should prompt for directory when none is provided', function () {
|
it('should prompt for directory when none is provided', function () {
|
||||||
return promiseWithTimeout(resolve => {
|
return promiseWithTimeout((resolve) => {
|
||||||
const {stdout} = setup()
|
const { stdout } = setup();
|
||||||
stdout.on('data', chunk => {
|
stdout.on('data', (chunk) => {
|
||||||
if (chunk.includes(instructions.directory)) {
|
if (chunk.includes(instructions.directory)) {
|
||||||
resolve()
|
resolve();
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
it ('should NOT proceed on a non-empty directory', function () {
|
it('should NOT proceed on a non-empty directory', function () {
|
||||||
return promiseWithTimeout(resolve => {
|
return promiseWithTimeout((resolve) => {
|
||||||
const {stdout} = setup([inputs.nonEmptyDir])
|
const { stdout } = setup([inputs.nonEmptyDir]);
|
||||||
stdout.on('data', chunk => {
|
stdout.on('data', (chunk) => {
|
||||||
if (chunk.includes(instructions.directory)) {
|
if (chunk.includes(instructions.directory)) {
|
||||||
resolve()
|
resolve();
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
it ('should proceed on an empty directory', async function () {
|
it('should proceed on an empty directory', async function () {
|
||||||
const resolvedEmptyDirPath = resolve(__dirname, inputs.emptyDir)
|
const resolvedEmptyDirPath = resolve(__dirname, inputs.emptyDir);
|
||||||
if (!existsSync(resolvedEmptyDirPath)) {
|
if (!existsSync(resolvedEmptyDirPath)) {
|
||||||
await promises.mkdir(resolvedEmptyDirPath)
|
await promises.mkdir(resolvedEmptyDirPath);
|
||||||
}
|
}
|
||||||
return promiseWithTimeout(resolve => {
|
return promiseWithTimeout((resolve) => {
|
||||||
const {stdout} = setup([inputs.emptyDir])
|
const { stdout } = setup([inputs.emptyDir]);
|
||||||
stdout.on('data', chunk => {
|
stdout.on('data', (chunk) => {
|
||||||
if (chunk.includes(instructions.template)) {
|
if (chunk.includes(instructions.template)) {
|
||||||
resolve()
|
resolve();
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
it ('should proceed when directory does not exist', function () {
|
it('should proceed when directory does not exist', function () {
|
||||||
return promiseWithTimeout(resolve => {
|
return promiseWithTimeout((resolve) => {
|
||||||
const {stdout} = setup([inputs.nonexistentDir])
|
const { stdout } = setup([inputs.nonexistentDir]);
|
||||||
stdout.on('data', chunk => {
|
stdout.on('data', (chunk) => {
|
||||||
if (chunk.includes(instructions.template)) {
|
if (chunk.includes(instructions.template)) {
|
||||||
resolve()
|
resolve();
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
it ('should error on bad directory selection in prompt', function () {
|
it('should error on bad directory selection in prompt', function () {
|
||||||
return promiseWithTimeout(resolve => {
|
return promiseWithTimeout((resolve) => {
|
||||||
const {stdout, stdin} = setup()
|
const { stdout, stdin } = setup();
|
||||||
stdout.on('data', chunk => {
|
stdout.on('data', (chunk) => {
|
||||||
if (chunk.includes('Please clear contents or choose a different path.')) {
|
if (chunk.includes('Please clear contents or choose a different path.')) {
|
||||||
resolve()
|
resolve();
|
||||||
}
|
}
|
||||||
if (chunk.includes(instructions.directory)) {
|
if (chunk.includes(instructions.directory)) {
|
||||||
stdin.write(`${inputs.nonEmptyDir}\x0D`)
|
stdin.write(`${inputs.nonEmptyDir}\x0D`);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
Loading…
Reference in a new issue