diff --git a/js/tests/verydisco-reverso_test.mjs b/js/tests/verydisco-reverso_test.mjs new file mode 100644 index 000000000..924593b6f --- /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 000000000..c6829686c --- /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) + + + +