|
|
@ -6,6 +6,7 @@ import { promisify } from 'util' |
|
|
|
const mkdir = fs.mkdir |
|
|
|
const mkdir = fs.mkdir |
|
|
|
const rmdir = fs.rmdir |
|
|
|
const rmdir = fs.rmdir |
|
|
|
const writeFile = fs.writeFile |
|
|
|
const writeFile = fs.writeFile |
|
|
|
|
|
|
|
const readFile = fs.readFile |
|
|
|
|
|
|
|
|
|
|
|
const exec = promisify(cp.exec) |
|
|
|
const exec = promisify(cp.exec) |
|
|
|
|
|
|
|
|
|
|
@ -87,7 +88,7 @@ const guests = [ |
|
|
|
'Gabriela Tucker', |
|
|
|
'Gabriela Tucker', |
|
|
|
'Kiri Wilcox', |
|
|
|
'Kiri Wilcox', |
|
|
|
] |
|
|
|
] |
|
|
|
const shuffle = arr => { |
|
|
|
const shuffle = (arr) => { |
|
|
|
let i = arr.length |
|
|
|
let i = arr.length |
|
|
|
let j, tmp |
|
|
|
let j, tmp |
|
|
|
while (--i > 0) { |
|
|
|
while (--i > 0) { |
|
|
@ -113,7 +114,7 @@ const getExpected = (list) => |
|
|
|
.map((g, i) => `${i + 1}. ${g}`) |
|
|
|
.map((g, i) => `${i + 1}. ${g}`) |
|
|
|
.join('\n') |
|
|
|
.join('\n') |
|
|
|
const generateObj = () => ({ |
|
|
|
const generateObj = () => ({ |
|
|
|
answer: ['yes', 'no'][Math.floor(Math.random() * 2)] |
|
|
|
answer: ['yes', 'no'][Math.floor(Math.random() * 2)], |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
export const setup = async () => { |
|
|
|
export const setup = async () => { |
|
|
@ -122,7 +123,9 @@ export const setup = async () => { |
|
|
|
// check if already exists and rm?
|
|
|
|
// check if already exists and rm?
|
|
|
|
await mkdir(`${dir}/${name}`) |
|
|
|
await mkdir(`${dir}/${name}`) |
|
|
|
const randomList = getRandomList(guests) |
|
|
|
const randomList = getRandomList(guests) |
|
|
|
const randomAnswers = Object.fromEntries(randomList.map(g => [g, generateObj()])) |
|
|
|
const randomAnswers = Object.fromEntries( |
|
|
|
|
|
|
|
randomList.map((g) => [g, generateObj()]), |
|
|
|
|
|
|
|
) |
|
|
|
const expected = getExpected(randomAnswers) |
|
|
|
const expected = getExpected(randomAnswers) |
|
|
|
await Promise.all( |
|
|
|
await Promise.all( |
|
|
|
Object.entries(randomAnswers).map( |
|
|
|
Object.entries(randomAnswers).map( |
|
|
@ -139,12 +142,15 @@ export const setup = async () => { |
|
|
|
} |
|
|
|
} |
|
|
|
const printVIPGuestList = async ({ arg, ctx, path, eq }) => { |
|
|
|
const printVIPGuestList = async ({ arg, ctx, path, eq }) => { |
|
|
|
const scriptPath = join(resolve(), path) |
|
|
|
const scriptPath = join(resolve(), path) |
|
|
|
|
|
|
|
const cwd = arg ? `${ctx.tmpPath}` : `${ctx.tmpPath}/${name}` |
|
|
|
const { stdout } = await exec(`node ${scriptPath} ${arg}`, { |
|
|
|
const { stdout } = await exec(`node ${scriptPath} ${arg}`, { |
|
|
|
cwd: arg ? `${ctx.tmpPath}` : `${ctx.tmpPath}/${name}`, |
|
|
|
cwd, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
const out = await readFile(`${cwd}/vip.txt`, 'utf8').catch((err) => |
|
|
|
// await rmdir(`${ctx.tmpPath}/${name}`, { recursive: true })
|
|
|
|
err.code === 'ENOENT' ? 'output file not found' : err, |
|
|
|
return eq(stdout.trim(), ctx.expected) |
|
|
|
) |
|
|
|
|
|
|
|
await exec(`rm vip.txt`, { cwd }) |
|
|
|
|
|
|
|
return eq(out, ctx.expected) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
tests.push(async ({ path, eq, ctx }) => { |
|
|
|
tests.push(async ({ path, eq, ctx }) => { |
|
|
|