From ec0d5f7b341c59f30f61294d6969cf55ee747678 Mon Sep 17 00:00:00 2001 From: Louise Foussat Date: Thu, 25 Feb 2021 18:02:27 +0000 Subject: [PATCH] piscine-js lite - node quest - exo 3: verydisco-reverso (add at least one test) --- js/tests/verydisco-reverso_test.mjs | 42 ++++++++++++++++++++++++++++ subjects/verydisco-reverso/README.md | 24 ++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 js/tests/verydisco-reverso_test.mjs create mode 100644 subjects/verydisco-reverso/README.md diff --git a/js/tests/verydisco-reverso_test.mjs b/js/tests/verydisco-reverso_test.mjs new file mode 100644 index 00000000..924593b6 --- /dev/null +++ b/js/tests/verydisco-reverso_test.mjs @@ -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) diff --git a/subjects/verydisco-reverso/README.md b/subjects/verydisco-reverso/README.md new file mode 100644 index 00000000..c6829686 --- /dev/null +++ b/subjects/verydisco-reverso/README.md @@ -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) + + + +