|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const{ promisify }=require('util'); |
| 4 | +constexec=promisify(require('child_process').exec); |
| 5 | +const{ copy, remove }=require('fs-extra'); |
| 6 | +constpath=require('path'); |
| 7 | +constassert=require('assert') |
| 8 | + |
| 9 | +constADDONS_FOLDER=path.join(__dirname,'addons'); |
| 10 | + |
| 11 | +constaddons=[ |
| 12 | +'echo addon', |
| 13 | +'echo-addon' |
| 14 | +] |
| 15 | + |
| 16 | +asyncfunctionbeforeAll(addons){ |
| 17 | +console.log(' >Preparing native addons to build') |
| 18 | +for(constaddonofaddons){ |
| 19 | +awaitremove(path.join(ADDONS_FOLDER,addon)); |
| 20 | +awaitcopy(path.join(__dirname,'tpl'),path.join(ADDONS_FOLDER,addon)); |
| 21 | +} |
| 22 | +} |
| 23 | + |
| 24 | +asyncfunctiontest(addon){ |
| 25 | +console.log(` >Building addon: '${addon}'`); |
| 26 | +const{ stderr, stdout }=awaitexec('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 | +constbinding=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=(asyncfunction(){ |
| 46 | +awaitbeforeAll(addons); |
| 47 | +for(constaddonofaddons){ |
| 48 | +awaittest(addon); |
| 49 | +} |
| 50 | +})() |
0 commit comments