node/test/parallel/test-fs-filehandle.js
Ruben Bridgewater baa4b9b425
test: refactor common.expectWarning()
The current API is somewhat confusing at times and simpler usage is
possible. This overloads the arguments further to accept objects
with deprecation codes as property keys. It also adds documentation
for the different possible styles.

Besides that it is now going to validate for the code being present
in case of deprecations but not for other cases. The former validation
was not consistent as it only validated some cases and accepted
undefined instead of `common.noWarnCode`. This check is removed due to
the lack of consistency. `common.noWarnCode` is completely removed
due to just being sugar for `undefined`.

This also verifies that the warning order is identical to the order
in which they are triggered.

PR-URL: https://github.com/nodejs/node/pull/25251
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2019-01-10 03:22:12 +01:00

34 lines
902 B
JavaScript

// Flags: --expose-gc --no-warnings --expose-internals
'use strict';
const common = require('../common');
const assert = require('assert');
const path = require('path');
const { internalBinding } = require('internal/test/binding');
const fs = internalBinding('fs');
const { stringToFlags } = require('internal/fs/utils');
// Verifies that the FileHandle object is garbage collected and that a
// warning is emitted if it is not closed.
let fdnum;
{
const ctx = {};
fdnum = fs.openFileHandle(path.toNamespacedPath(__filename),
stringToFlags('r'), 0o666, undefined, ctx).fd;
assert.strictEqual(ctx.errno, undefined);
}
common.expectWarning({
'internal/test/binding': [
'These APIs are for internal testing only. Do not use them.'
],
'Warning': [
`Closing file descriptor ${fdnum} on garbage collection`
]
});
global.gc();
setTimeout(() => {}, 10);