Skip to content

Commit

Permalink
Creates e2e tests
Browse files Browse the repository at this point in the history
* Validates vercel build deps
  • Loading branch information
joncloud committed Sep 11, 2022
1 parent df78158 commit 952ce59
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 19 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ jobs:
run: npm ci

- name: 'Test'
run: |
npm test -- --reporter json --reporter-options output=${{ runner.temp }}/report-${{ matrix.os }}.json
cat ${{ runner.temp }}/report-${{ matrix.os }}.json | jq
run: npm test -- --reporter json --reporter-options output=${{ runner.temp }}/report-${{ matrix.os }}.json

- name: 'Print Tests'
# run this step even if previous step failed
if: (success() || failure())
run: cat ${{ runner.temp }}/report-${{ matrix.os }}.json | jq

- name: 'Publish Tests'
uses: 'dorny/test-reporter@v1'
Expand Down
32 changes: 17 additions & 15 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ exports.addPath = addPath;
* @returns string
*/
function getInput(name, options) {
const key = `INPUT_${name.replace(/ /g, '_').toUpperCase()}`;
const val = process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || '';
console.log('core/getInput', { key, val });
if (options && options.required && !val) {
throw new Error(`Input required and not supplied: ${name}`);
}
Expand Down Expand Up @@ -533,8 +535,8 @@ class OidcClient {
const res = yield httpclient
.getJson(id_token_url)
.catch(error => {
throw new Error(`Failed to get ID Token. \n
Error Code : ${error.statusCode}\n
throw new Error(`Failed to get ID Token. \n
Error Code : ${error.statusCode}\n
Error Message: ${error.result.message}`);
});
const id_token = (_a = res.result) === null || _a === void 0 ? void 0 : _a.value;
Expand Down Expand Up @@ -2075,7 +2077,7 @@ const makensis = __nccwpck_require__(598);
*/
const isDirectoryAsync = async (item) => {
const stats = await fs.stat(item);

return stats.isDirectory();
};

Expand All @@ -2089,7 +2091,7 @@ const fileExistsAsync = async (item) => {
} catch (err) {
return false;
}

return true;
}

Expand Down Expand Up @@ -2191,7 +2193,7 @@ class Installer {
args.push('-V1');
}
}

args.push(this.customArguments);
args.push(`"${path.resolve(scriptPath)}"`);

Expand All @@ -2214,7 +2216,7 @@ class Installer {
}
const nsisPluginPath = path.join(nsisdir, 'Plugins');
this.debugLog(`Using system Plugins path ${nsisPluginPath}`);

const copies = this.pluginPaths.map(pluginPath => {
console.log('Including plugin path', pluginPath);
return copyDirectoryAsync(pluginPath, nsisPluginPath);
Expand Down Expand Up @@ -2319,14 +2321,14 @@ class Makensis {
*/
async getSymbolsAsync() {
const buffer = await this.execAsync('-HDRINFO');

// Look for the defined symbols in the output.
const exp = /Defined symbols: (.*)/g;
const matches = exp.exec(buffer.toString('utf-8'));
if (!matches || !matches.length || matches.length < 2) {
throw new Error('Unable to get symbols');
}

// Create a map of all of the symbols.
const symbols = { };

Expand Down Expand Up @@ -2482,7 +2484,7 @@ module.exports = require("util");
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/
/******/ // The require function
/******/ function __nccwpck_require__(moduleId) {
/******/ // Check if module is in cache
Expand All @@ -2496,7 +2498,7 @@ module.exports = require("util");
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/
/******/ // Execute the module function
/******/ var threw = true;
/******/ try {
Expand All @@ -2505,16 +2507,16 @@ module.exports = require("util");
/******/ } finally {
/******/ if(threw) delete __webpack_module_cache__[moduleId];
/******/ }
/******/
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat */
/******/
/******/
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";
/******/
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be in strict mode.
Expand Down Expand Up @@ -2572,4 +2574,4 @@ run();

module.exports = __webpack_exports__;
/******/ })()
;
;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "dist/index.js",
"scripts": {
"build": "ncc build -o dist src/index.js",
"test": "mocha --reporter spec --timeout 5000"
"test": "mocha --reporter spec --timeout 5000 test/**.spec.js"
},
"repository": {
"type": "git",
Expand Down
16 changes: 16 additions & 0 deletions test/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

const args = process.argv.splice(2);
for (let i = 0; i < args.length; i += 2) {
const key = args[i];
const value = args[i + 1];
if (!value) {
console.warn('missing arg value for', key);
continue;
}

console.log('assigning arg to env', key, value);
process.env[key] = value;
}

require('../dist');
115 changes: 115 additions & 0 deletions test/e2e.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
'use strict';

const assert = require('assert');
const { exec } = require('child_process');
const { access, unlink } = require('fs/promises');
const path = require('path');

const exists = async (path) => {
try {
await access(path);
return true;
}
catch {
return false;
}
};

/**
* @param {string} path
*/
const unlinkIfExistsAsync = async (path) => {
if (await exists(path)) {
unlink(path);
}
};

describe('e2e', () => {
before(async () => {
const promises = ['./basic.exe', './with-plugins.exe']
.map(unlinkIfExistsAsync);

await Promise.all(promises);
});

/**
* @typedef {{
* customArguments?: string,
* additionalPluginPaths?: string[],
* scriptFile?: string,
* }} RunOptions
* @param {RunOptions} options
*/
const run = async (options = {}) => {
const {
customArguments,
additionalPluginPaths,
scriptFile
} = options;

const args = [];
const env = {
...process.env,
debug: 'true',
};
if (customArguments) {
args.push('INPUT_ARGUMENTS', customArguments);
}
if (additionalPluginPaths && additionalPluginPaths.length) {
args.push('INPUT_ADDITIONAL-PLUGIN-PATHS', additionalPluginPaths.join('\n'));
}
if (scriptFile) {
args.push('INPUT_SCRIPT-FILE', scriptFile);
}

const programPath = require.resolve('./bootstrap');
const testDir = path.dirname(programPath);
const cwd = path.join(testDir, '../');
const promise = new Promise((resolve, reject) => {
exec(`node ${programPath} ${args.join(' ')}`, {
env,
cwd,
}, (error, stdout, stderr) => {
console.log('cwd', cwd);
console.log('stdout', stdout);
console.log('stderr', stderr);
if (error) {
reject(error);
} else {
resolve();
}
});
});

await promise;
};

/**
* @param {string} script
* @param {(options: RunOptions) => void} fn
*/
const test = (script, fn) => {
it(`should create installer for ${script}.nsi`, async () => {
const options = {
scriptFile: `./test/${script}.nsi`
};
if (fn) {
fn(options);
}

await run(options);

const actual = await exists(`./test/${script}.exe`);

assert(
actual,
`Installer \`./test/${script}.exe\` should exist`
);
});
};

test('basic');
test('with-plugins', options => options.additionalPluginPaths = [
'./test/EnVar'
]);
});

0 comments on commit 952ce59

Please sign in to comment.