Skip to content
This repository has been archived by the owner on Aug 31, 2018. It is now read-only.

Commit

Permalink
test: skip test-process-config if no config.gypi
Browse files Browse the repository at this point in the history
If you run the tests in a different machine to the one you built on,
this test will fail. Avoid this by skipping if the file doesn't exist.
We shouldn't need to check that the file exists in this test, as the
build won't pass without a config.gypi anyway.

Also adds console.logs, so you can see what the actual difference
between the objects was, as `assert.deepStrictEqual()` only shows you
the first three lines.

PR-URL: nodejs/node#16436
Reviewed-By: Gireesh Punathil <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
gibfahn authored and Qard committed Nov 2, 2017
1 parent 106f1a8 commit add0859
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions test/parallel/test-process-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,45 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
require('../common');

const common = require('../common');

// Checks that the internal process.config is equivalent to the config.gypi file
// created when we run configure.

const assert = require('assert');
const fs = require('fs');
const path = require('path');

// check for existence
// Check for existence of `process.config`.
assert(process.hasOwnProperty('config'));

// ensure that `process.config` is an Object
// Ensure that `process.config` is an Object.
assert.strictEqual(Object(process.config), process.config);

const configPath = path.resolve(__dirname, '..', '..', 'config.gypi');

if (!fs.existsSync(configPath)) {
common.skip('config.gypi does not exist.');
}

let config = fs.readFileSync(configPath, 'utf8');

// clean up comment at the first line
// Clean up comment at the first line.
config = config.split('\n').slice(1).join('\n').replace(/'/g, '"');
config = JSON.parse(config, function(key, value) {
if (value === 'true') return true;
if (value === 'false') return false;
return value;
});

assert.deepStrictEqual(config, process.config);
try {
assert.deepStrictEqual(config, process.config);
} catch (e) {
// If the assert fails, it only shows 3 lines. We need all the output to
// compare.
console.log('config:', config);
console.log('process.config:', process.config);

throw e;
}

0 comments on commit add0859

Please sign in to comment.