mirror of https://github.com/01-edu/public.git
rm big random in tell-me-who tests
This commit is contained in:
parent
f71ce9d07b
commit
25ab1365f2
|
@ -7,65 +7,15 @@ import { promisify } from 'util'
|
||||||
const exec = promisify(cp.exec)
|
const exec = promisify(cp.exec)
|
||||||
|
|
||||||
export const tests = []
|
export const tests = []
|
||||||
|
|
||||||
// maybe get the sames from an api? like https://parser.name/
|
|
||||||
const guests = [
|
|
||||||
'Shyam Langley',
|
|
||||||
'Zishan Randolph',
|
|
||||||
'Connor Connolly',
|
|
||||||
'Edna Floyd',
|
|
||||||
'Robyn Jimenez',
|
|
||||||
'Carly Alexander',
|
|
||||||
'Jed Newman',
|
|
||||||
'Marianna Sullivan',
|
|
||||||
'Glyn Townsend',
|
|
||||||
'Montana Mooney',
|
|
||||||
'Amelia-Rose Trejo',
|
|
||||||
'Micah Whittle',
|
|
||||||
'Nola Sherman',
|
|
||||||
'Gregory Vu',
|
|
||||||
'Lili Griffiths',
|
|
||||||
'Tasnia Hughes',
|
|
||||||
'Trixie Pennington',
|
|
||||||
'Ava Meyer',
|
|
||||||
'Gabriela Tucker',
|
|
||||||
'Kiri Wilcox',
|
|
||||||
]
|
|
||||||
const shuffle = (arr) => {
|
|
||||||
let i = arr.length
|
|
||||||
let j, tmp
|
|
||||||
while (--i > 0) {
|
|
||||||
j = Math.floor(Math.random() * (i + 1))
|
|
||||||
tmp = arr[j]
|
|
||||||
arr[j] = arr[i]
|
|
||||||
arr[i] = tmp
|
|
||||||
}
|
|
||||||
return arr
|
|
||||||
}
|
|
||||||
const ranStr = () =>
|
const ranStr = () =>
|
||||||
Math.random()
|
Math.random()
|
||||||
.toString(36)
|
.toString(36)
|
||||||
.substring(7)
|
.substring(7)
|
||||||
const getRandomList = (names) =>
|
|
||||||
shuffle(names).slice(0, Math.floor(Math.random() * (names.length - 10) + 10))
|
|
||||||
const getExpected = (list) =>
|
|
||||||
list
|
|
||||||
.map((g) =>
|
|
||||||
g
|
|
||||||
.split(' ')
|
|
||||||
.reverse()
|
|
||||||
.join(' '),
|
|
||||||
)
|
|
||||||
.sort()
|
|
||||||
.map((g, i) => `${i + 1}. ${g}`)
|
|
||||||
.join('\n')
|
|
||||||
|
|
||||||
export const setup = async ({ path }) => {
|
export const setup = async ({ path }) => {
|
||||||
const dir = `${tmpdir()}/tell-me-who`
|
const dir = `${tmpdir()}/tell-me-who`
|
||||||
|
|
||||||
await mkdir(dir)
|
await mkdir(dir)
|
||||||
const randomList = getRandomList(guests)
|
|
||||||
const expected = getExpected(randomList)
|
|
||||||
|
|
||||||
const createFilesIn = async ({ fileNames, folderPath }) =>
|
const createFilesIn = async ({ fileNames, folderPath }) =>
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
|
@ -73,10 +23,6 @@ export const setup = async ({ path }) => {
|
||||||
async (fileName) => await writeFile(`${folderPath}/${fileName}`, ''),
|
async (fileName) => await writeFile(`${folderPath}/${fileName}`, ''),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
await createFilesIn({
|
|
||||||
fileNames: randomList.map((n) => `${n.replace(' ', '_')}.json`),
|
|
||||||
folderPath: dir,
|
|
||||||
})
|
|
||||||
|
|
||||||
const run = async (cmd) => {
|
const run = async (cmd) => {
|
||||||
const cmdPath = isAbsolute(cmd || '') ? cmd : join(dir, cmd || '')
|
const cmdPath = isAbsolute(cmd || '') ? cmd : join(dir, cmd || '')
|
||||||
|
@ -85,53 +31,34 @@ export const setup = async ({ path }) => {
|
||||||
return { stdout: stdout.trim() }
|
return { stdout: stdout.trim() }
|
||||||
}
|
}
|
||||||
|
|
||||||
return { tmpPath: dir, expected, run, createFilesIn }
|
return { tmpPath: dir, run, createFilesIn }
|
||||||
}
|
}
|
||||||
|
|
||||||
tests.push(async ({ path, eq, ctx }) => {
|
tests.push(async ({ path, eq, ctx }) => {
|
||||||
|
const random = ranStr()
|
||||||
const fileNames = [
|
const fileNames = [
|
||||||
'Ubaid_Ballard.json',
|
'Ubaid_Ballard.json',
|
||||||
'Victoria_Chan.json',
|
'Victoria_Chan.json',
|
||||||
'Dominika_Mullen.json',
|
'Dominika_Mullen.json',
|
||||||
'Heath_Denton.json',
|
'Heath_Denton.json',
|
||||||
'Lilith_Hamilton.json',
|
`${random}_Hamilton.json`,
|
||||||
]
|
]
|
||||||
const folderName = `tell-me-who-${ranStr()}`
|
const folderName = `them-${ranStr()}`
|
||||||
const folderPath = join(ctx.tmpPath, `../${folderName}`)
|
const folderPath = join(ctx.tmpPath, folderName)
|
||||||
await mkdir(folderPath)
|
await mkdir(folderPath)
|
||||||
await ctx.createFilesIn({ folderPath, fileNames })
|
await ctx.createFilesIn({ folderPath, fileNames })
|
||||||
|
|
||||||
const { stdout } = await ctx.run(`../${folderName}`)
|
const { stdout } = await ctx.run(folderName)
|
||||||
return eq(
|
return eq(
|
||||||
[
|
[
|
||||||
`1. Ballard Ubaid`,
|
`1. Ballard Ubaid`,
|
||||||
`2. Chan Victoria`,
|
`2. Chan Victoria`,
|
||||||
`3. Denton Heath`,
|
`3. Denton Heath`,
|
||||||
`4. Hamilton Lilith`,
|
`4. Hamilton ${random}`,
|
||||||
`5. Mullen Dominika`,
|
`5. Mullen Dominika`,
|
||||||
],
|
],
|
||||||
stdout.split('\n'),
|
stdout.split('\n'),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
tests.push(async ({ path, eq, ctx }) => {
|
|
||||||
// will execute the script in a folder named `tell-me-who`
|
|
||||||
// '../tell-me-who' in the argument passed
|
|
||||||
// `tell-me-who` folder has a random file number
|
|
||||||
const { stdout } = await ctx.run('../tell-me-who')
|
|
||||||
return eq(stdout, ctx.expected)
|
|
||||||
})
|
|
||||||
|
|
||||||
tests.push(async ({ path, eq, ctx }) => {
|
|
||||||
// will execute the script without argument
|
|
||||||
const { stdout } = await ctx.run()
|
|
||||||
return eq(stdout, ctx.expected)
|
|
||||||
})
|
|
||||||
|
|
||||||
tests.push(async ({ path, eq, ctx }) => {
|
|
||||||
// will execute the script with `tell-me-who` folder's absolute path as argument
|
|
||||||
const { stdout } = await ctx.run(ctx.tmpPath)
|
|
||||||
return eq(stdout, ctx.expected)
|
|
||||||
})
|
|
||||||
|
|
||||||
Object.freeze(tests)
|
Object.freeze(tests)
|
||||||
|
|
Loading…
Reference in New Issue