Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tests #34

Merged
merged 7 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@
"fix": "npm run lint:style -- -w && npm run lint:code -- --fix",
"prepare": "npm run build",
"prepublishOnly": "npm run lint",
"test": "npm run build && npm run test:18 && npm run test:16 && npm run test:14 && npm run test:host",
"test": "npm run build && npm run test:18 && npm run test:16 && npm run test:host",
"test:20": "node test/test.js node20 no-npm",
"test:18": "node test/test.js node18 no-npm",
"test:16": "node test/test.js node16 no-npm",
"test:14": "node test/test.js node14 no-npm",
"test:host": "node test/test.js host only-npm",
"release": "read -p 'GITHUB_TOKEN: ' GITHUB_TOKEN && export GITHUB_TOKEN=$GITHUB_TOKEN && release-it"
},
Expand Down
1 change: 1 addition & 0 deletions test/test-79-npm/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const npm = {
14: 6,
16: 7,
18: 8,
20: 10,
}[hostVersion];

assert(npm !== undefined);
Expand Down
60 changes: 44 additions & 16 deletions test/test-80-compression-node-opcua/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const fs = require('fs');
const path = require('path');
const assert = require('assert');
const utils = require('../utils.js');
const pkgJson = require('./package.json');

const buildDir = 'build';

assert(!module.parent);
assert(__dirname === process.cwd());
Expand All @@ -20,9 +23,14 @@ if (utils.shouldSkipPnpm()) {
return;
}

function clean() {
utils.vacuum.sync(buildDir);
utils.vacuum.sync('node_modules');
utils.vacuum.sync('./pnpm-lock.yaml');
}

// remove any possible left-over
utils.vacuum.sync('./node_modules');
utils.vacuum.sync('./pnpm-lock.yaml');
clean();

// launch `pnpm install`
const pnpmlog = utils.spawn.sync(
Expand All @@ -47,11 +55,11 @@ assert(
const input = 'package.json';
const target = process.argv[2] || 'host';
const ext = process.platform === 'win32' ? '.exe' : '';
const outputRef = 'test-output-empty' + ext;
const outputNone = 'test-output-None' + ext;
const outputGZip = 'test-output-GZip' + ext;
const outputBrotli = 'test-output-Brotli' + ext;
const outputBrotliDebug = 'test-output-Brotli-debug' + ext;
const outputRef = path.join(buildDir, 'test-output-empty' + ext);
const outputNone = path.join(buildDir, 'test-output-None' + ext);
const outputGZip = path.join(buildDir, 'test-output-GZip' + ext);
const outputBrotli = path.join(buildDir, 'test-output-Brotli' + ext);
const outputBrotliDebug = path.join(buildDir, 'test-output-Brotli-debug' + ext);

const inspect = ['ignore', 'ignore', 'pipe'];

Expand All @@ -78,13 +86,40 @@ function pkgCompress(compressMode, output) {
);
// check that produced executable is running and produce the expected output.
const log = utils.spawn.sync(path.join(__dirname, output), [], {
cwd: __dirname,
cwd: path.join(__dirname, buildDir),
expect: 0,
});
assert(log === '42\n');
return fs.statSync(output).size;
}

function esbuildBuild(entryPoint) {
const log = utils.spawn.sync(
path.join(
path.dirname(process.argv[0]),
'npx' + (process.platform === 'win32' ? '.cmd' : ''),
),
[
'esbuild',
entryPoint,
'--bundle',
'--outfile=' + path.join(buildDir, pkgJson.main),
'--platform=node',
],
{ cwd: __dirname, expect: 0 },
);

console.log(log);

// copy folder 'node_modules/node-opcua-nodesets' to build folder
utils.copyRecursiveSync(
'node_modules/node-opcua-nodesets/nodesets',
path.join(buildDir, 'nodesets'),
);
}

esbuildBuild(pkgJson.main);

const sizeNoneFull = pkgCompress('None', outputNone);
const sizeGZipFull = pkgCompress('GZip', outputGZip);
const sizeBrotliFull = pkgCompress('Brotli', outputBrotli);
Expand Down Expand Up @@ -121,15 +156,8 @@ const logPkg5 = utils.pkg.sync(
{ expect: 2 },
);

// xx console.log(logPkg4);
assert(logPkg5.match(/Invalid compression algorithm/g));

utils.vacuum.sync(outputRef);
utils.vacuum.sync(outputNone);
utils.vacuum.sync(outputBrotli);
utils.vacuum.sync(outputGZip);
utils.vacuum.sync(outputBrotliDebug);
utils.vacuum.sync('node_modules');
utils.vacuum.sync('./pnpm-lock.yaml');
clean();

console.log('OK');
5 changes: 4 additions & 1 deletion test/test-80-compression-node-opcua/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "test-12-compression",
"version": "1.0.0",
"description": "",
"bin": "build/test-x.js",
"main": "test-x.js",
"scripts": {
"preinstall": "npx only-allow pnpm",
Expand All @@ -15,7 +16,9 @@
"node-opcua-crypto": "^1.7.1",
"node-opcua-nodesets": "^2.36.0"
},
"bin": "test-x.js",
"devDependencies": {
"esbuild": "^0.20.0"
},
"pkg": {
"assets": [
"./node_modules/node-opcua-nodesets/nodesets/*.xml"
Expand Down
18 changes: 17 additions & 1 deletion test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const rimraf = require('rimraf');
const globby = require('globby');
const { execSync } = require('child_process');
const { spawnSync } = require('child_process');
const { existsSync } = require('fs');
const { existsSync, statSync, copyFileSync, readdirSync } = require('fs');
const stableStringify = require('json-stable-stringify');

module.exports.mkdirp = mkdirp;
Expand All @@ -20,6 +20,22 @@ module.exports.pause = function (seconds) {
]);
};

module.exports.copyRecursiveSync = function (origin, dest) {
const stats = statSync(origin);
if (stats.isDirectory()) {
mkdirp.sync(dest);
const files = readdirSync(origin);
for (const file of files) {
module.exports.copyRecursiveSync(
path.join(origin, file),
path.join(dest, file),
);
}
} else {
copyFileSync(origin, dest);
}
};

module.exports.vacuum = function () {
throw new Error('Async vacuum not implemented');
};
Expand Down
Loading