mirror of
https://github.com/nodejs/node.git
synced 2025-05-13 10:54:13 +00:00

The `test/common` module has the capability to identify if any variable is leaked to the global scope and fail the test. So that has to be imported at the beginning. PR-URL: https://github.com/nodejs/node/pull/7786 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
28 lines
666 B
JavaScript
28 lines
666 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const dirName = path.resolve(common.fixturesDir, 'test-readfile-unlink');
|
|
const fileName = path.resolve(dirName, 'test.bin');
|
|
|
|
var buf = Buffer.alloc(512 * 1024, 42);
|
|
|
|
try {
|
|
fs.mkdirSync(dirName);
|
|
} catch (e) {
|
|
// Ignore if the directory already exists.
|
|
if (e.code != 'EEXIST') throw e;
|
|
}
|
|
|
|
fs.writeFileSync(fileName, buf);
|
|
|
|
fs.readFile(fileName, function(err, data) {
|
|
assert.ifError(err);
|
|
assert(data.length == buf.length);
|
|
assert.strictEqual(buf[0], 42);
|
|
|
|
fs.unlinkSync(fileName);
|
|
fs.rmdirSync(dirName);
|
|
});
|