mirror of https://github.com/01-edu/public.git
piscine-js lite - node quest - exo 3: verydisco-reverso (add at least one test)
This commit is contained in:
parent
8568163a53
commit
ec0d5f7b34
|
@ -0,0 +1,42 @@
|
|||
import fs from 'fs/promises'
|
||||
const readFile = fs.readFile
|
||||
const writeFile = fs.writeFile
|
||||
import { promisify } from 'util'
|
||||
import * as cp from 'child_process'
|
||||
|
||||
const exec = promisify(cp.exec)
|
||||
|
||||
export const tests = []
|
||||
const name = 'verydisco-reverso'
|
||||
const hasContentAndExpect = async ({ content, expect, path, eq }) => {
|
||||
const cwd = `${path
|
||||
.split('/')
|
||||
.slice(0, -1)
|
||||
.join('/')}/`
|
||||
|
||||
await writeFile(`${cwd}${name}.txt`, content, 'utf8')
|
||||
const { stdout } = await exec(`node ${name}.mjs "${name}.txt"`, { cwd })
|
||||
await exec(`rm ${name}.txt`, { cwd })
|
||||
|
||||
return eq(stdout.trim(), expect)
|
||||
}
|
||||
|
||||
tests.push(async ({ path, eq }) =>
|
||||
hasContentAndExpect({
|
||||
path,
|
||||
eq,
|
||||
content: `deNo si omeawes`,
|
||||
expect: 'Node is awesome',
|
||||
}),
|
||||
)
|
||||
|
||||
// tests.push(async ({ path, eq }) => {
|
||||
// await hasContentAndExpect({
|
||||
// path,
|
||||
// eq,
|
||||
// content: // newfilename,
|
||||
// expect: // reverso
|
||||
// })
|
||||
// })
|
||||
|
||||
Object.freeze(tests)
|
|
@ -0,0 +1,24 @@
|
|||
## verydisco-reverso
|
||||
|
||||
### Instructions
|
||||
|
||||
Create a `verydisco-reverso.mjs` script that:
|
||||
- takes the name of a file (with extension) in argument
|
||||
- read this file
|
||||
- discover the content of this file by reversing it from the `very disco` mode
|
||||
- print the result in console
|
||||
|
||||
For example:
|
||||
- Reading the `verydisco` content of your `verydisco.txt` file would print `discovery` in console.
|
||||
|
||||
### Notions
|
||||
|
||||
- [Node file system: `readFile`](https://nodejs.org/api/fs.html#fs_fspromises_writefile_file_data_options)
|
||||
<!-- and also Math.floors ? -->
|
||||
<!--
|
||||
again?
|
||||
- [Node path: `resolve`](https://nodejs.org/api/path.html#path_path_resolve_paths)
|
||||
- [Node path: `join`](https://nodejs.org/api/path.html#path_path_join_paths)
|
||||
-->
|
||||
|
||||
|
Loading…
Reference in New Issue