|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const { promisify } = require('util'); |
| 4 | +const exec = promisify(require('child_process').exec); |
| 5 | +const { copy, remove } = require('fs-extra'); |
| 6 | +const path = require('path'); |
| 7 | +const assert = require('assert') |
| 8 | + |
| 9 | +const ADDONS_FOLDER = path.join(__dirname, 'addons'); |
| 10 | + |
| 11 | +const addons = [ |
| 12 | + 'echo addon', |
| 13 | + 'echo-addon' |
| 14 | +] |
| 15 | + |
| 16 | +async function beforeAll(addons) { |
| 17 | + console.log(' >Preparing native addons to build') |
| 18 | + for (const addon of addons) { |
| 19 | + await remove(path.join(ADDONS_FOLDER, addon)); |
| 20 | + await copy(path.join(__dirname, 'tpl'), path.join(ADDONS_FOLDER, addon)); |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +async function test(addon) { |
| 25 | + console.log(` >Building addon: '${addon}'`); |
| 26 | + const { stderr, stdout } = await exec('npm install', { |
| 27 | + cwd: path.join(ADDONS_FOLDER, addon) |
| 28 | + }) |
| 29 | + console.log(` >Runting test for: '${addon}'`); |
| 30 | + // Disabled the checks on stderr and stdout because of this issuue on npm: |
| 31 | + // Stop using process.umask(): https://github.com/npm/cli/issues/1103 |
| 32 | + // We should enable the following checks again after the resolution of |
| 33 | + // the reported issue. |
| 34 | + // assert.strictEqual(stderr, ''); |
| 35 | + // assert.ok(stderr.length === 0); |
| 36 | + // assert.ok(stdout.length > 0); |
| 37 | + const binding = require(`${ADDONS_FOLDER}/${addon}`); |
| 38 | + assert.strictEqual(binding.except.echo('except'), 'except'); |
| 39 | + assert.strictEqual(binding.except.echo(101), 101); |
| 40 | + assert.strictEqual(binding.noexcept.echo('noexcept'), 'noexcept'); |
| 41 | + assert.strictEqual(binding.noexcept.echo(103), 103); |
| 42 | +} |
| 43 | + |
| 44 | + |
| 45 | +module.exports = (async function() { |
| 46 | + await beforeAll(addons); |
| 47 | + for (const addon of addons) { |
| 48 | + await test(addon); |
| 49 | + } |
| 50 | +})() |
0 commit comments