workshopper / stream-adventure

go on an educational stream adventure!
Other
2.06k stars 313 forks source link

TypeError while running Exercise 13 (DUPLEXER) and 14 (DUPLEXER REDUX) #271

Open antosant1981 opened 2 years ago

antosant1981 commented 2 years ago

Hello,

I had the follwing error while trying ro run (and verify) exercises 13 and 14:

this.submissionChild = this.submissionFn(this.submissionArgs)
                                ^
TypeError: this.submissionFn is not a function
    at Exercise.<anonymous> (C:\Users\anton\AppData\Roaming\npm\node_modules\stream-adventure\lib\exportFnExercise.js:29:33)
    at next (C:\Users\anton\AppData\Roaming\npm\node_modules\stream-adventure\node_modules\workshopper-exercise\exercise.js:170:19)
    at Exercise.process (C:\Users\anton\AppData\Roaming\npm\node_modules\stream-adventure\node_modules\workshopper-exercise\exercise.js:177:5)
    at Exercise.<anonymous> (C:\Users\anton\AppData\Roaming\npm\node_modules\stream-adventure\node_modules\workshopper-exercise\exercise.js:147:10)
    at processTicksAndRejections (node:internal/process/task_queues:78:11)

Find below the code of the challenge 13.

This is the script with the function to export (named child.js):

const { spawn } = require('child_process');
const duplexer2 = require('duplexer2');

module.exports = function (cmd, args, opts) {
    // spawn the process and return a single stream
    const command = spawn(cmd, args, opts);

    // readable is obtained using the command stdout
    const readable = command.stdout;

    // writable is obtained using the command stdin
    const writable = command.stdin;

    // joining together the stdin and stdout here
    return duplexer2(writable, readable);
  }

This is the script that uses the function exported:

const child = require('./child');

const command = child('dir', [], { shell: true });

command.pipe(process.stdout);

Can you tell me what's wrong please and possibly suggest a solution?

ccarruitero commented 2 years ago

Hi @antosant1981

Your solution (exported function) seems correct.

Not sure how you are running the verify script? You just need to run the verify script with your function file as parameter.