1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

child_process.exec を使ってみた

Last updated at Posted at 2019-08-30

元ネタは現代の JavaScript チュートリアル

sync_iterator.js
'use strict';

let range = {
  from: 1,
  to: 5,

  [Symbol.iterator]() {
    return {
      current: this.from,
      last: this.to,
      next() {
        if (this.current <= this.last)
          return { done: false, value: this.current++ };
        else
          return { done: true }
      }
    }
  }
}

for (const value of range) console.log(value);
test.js
'use strict';

const assert = require('assert');
const child_process = require('child_process');

describe('Async iterator', () => {
  it('should output sequence', done => {
    child_process.exec('node ./async_iterator.js', (error, stdout) => {
      assert.equal(stdout, '1\n2\n3\n4\n5\n');
      done();
    });
  });
});

参考にしたページ

Child Process | Node.js v12.9.1 Documentation

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?