Skip to content

Commit

Permalink
add prettier
Browse files Browse the repository at this point in the history
add prettier to bring consistent style.
  • Loading branch information
gengjiawen committed Nov 18, 2018
1 parent efa5bf9 commit 517c95c
Show file tree
Hide file tree
Showing 2,193 changed files with 67,859 additions and 50,688 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,5 @@ deps/v8/gypfiles/Release/
deps/v8/third_party/eu-strip/

.DS_Store

node_modules
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"scripts": {
"format": "prettier --write \"{src,test}/**/*.{js,ts}\"",
"format:check": "prettier --list-different \"{src,test}/**/*.{js,ts}\""
},
"dependencies": {
"prettier": "^1.15.2"
}
}
5 changes: 4 additions & 1 deletion test/abort/test-abort-backtrace.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ if (process.argv[2] === 'child') {
assert.strictEqual(child.stdout.toString(), '');
// stderr will be empty for systems that don't support backtraces.
if (stderr !== '') {
const frames = stderr.trimRight().split('\n').map((s) => s.trim());
const frames = stderr
.trimRight()
.split('\n')
.map((s) => s.trim());

if (!frames.every((frame, index) => frame.startsWith(`${index + 1}:`))) {
assert.fail(`Each frame should start with a frame number:\n${stderr}`);
Expand Down
35 changes: 19 additions & 16 deletions test/abort/test-abort-uncaught-exception.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,30 @@ if (process.argv[2] === 'child') {
new vm.Script('[', {});
} else {
run('', 'child', null);
run('--abort-on-uncaught-exception', 'child',
['SIGABRT', 'SIGTRAP', 'SIGILL']);
run('--abort-on-uncaught-exception', 'child', [
'SIGABRT',
'SIGTRAP',
'SIGILL'
]);
run('--abort-on-uncaught-exception', 'vm', ['SIGABRT', 'SIGTRAP', 'SIGILL']);
}

function run(flags, argv2, signals) {
const args = [__filename, argv2];
if (flags)
args.unshift(flags);
if (flags) args.unshift(flags);

const child = spawn(node, args);
child.on('exit', common.mustCall(function(code, sig) {
if (common.isWindows) {
if (signals)
assert.strictEqual(code, 0xC0000005);
else
assert.strictEqual(code, 1);
} else if (signals) {
assert(signals.includes(sig), `Unexpected signal ${sig}`);
} else {
assert.strictEqual(sig, null);
}
}));
child.on(
'exit',
common.mustCall(function(code, sig) {
if (common.isWindows) {
if (signals) assert.strictEqual(code, 0xc0000005);
else assert.strictEqual(code, 1);
} else if (signals) {
assert(signals.includes(sig), `Unexpected signal ${sig}`);
} else {
assert.strictEqual(sig, null);
}
})
);
}
52 changes: 33 additions & 19 deletions test/abort/test-addon-uv-handle-leak.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,33 @@ const { spawnSync } = require('child_process');
// This is a sibling test to test/addons/uv-handle-leak.

const bindingPath = path.resolve(
__dirname, '..', 'addons', 'uv-handle-leak', 'build',
`${common.buildType}/binding.node`);
__dirname,
'..',
'addons',
'uv-handle-leak',
'build',
`${common.buildType}/binding.node`
);

if (!fs.existsSync(bindingPath))
common.skip('binding not built yet');
if (!fs.existsSync(bindingPath)) common.skip('binding not built yet');

if (process.argv[2] === 'child') {
new Worker(`
new Worker(
`
const binding = require(${JSON.stringify(bindingPath)});
binding.leakHandle();
binding.leakHandle(0);
binding.leakHandle(0x42);
`, { eval: true });
`,
{ eval: true }
);
} else {
const child = cp.spawnSync(process.execPath,
['--experimental-worker', __filename, 'child']);
const child = cp.spawnSync(process.execPath, [
'--experimental-worker',
__filename,
'child'
]);
const stderr = child.stderr.toString();

assert.strictEqual(child.stdout.toString(), '');
Expand All @@ -53,23 +63,27 @@ if (process.argv[2] === 'child') {
function isGlibc() {
try {
const lddOut = spawnSync('ldd', [process.execPath]).stdout;
const libcInfo = lddOut.toString().split('\n').map(
(line) => line.match(/libc\.so.+=>\s*(\S+)\s/)).filter((info) => info);
if (libcInfo.length === 0)
return false;
const libcInfo = lddOut
.toString()
.split('\n')
.map((line) => line.match(/libc\.so.+=>\s*(\S+)\s/))
.filter((info) => info);
if (libcInfo.length === 0) return false;
const nmOut = spawnSync('nm', ['-D', libcInfo[0][1]]).stdout;
if (/gnu_get_libc_version/.test(nmOut))
return true;
if (/gnu_get_libc_version/.test(nmOut)) return true;
} catch {
return false;
}
}


if (!(common.isFreeBSD ||
common.isAIX ||
(common.isLinux && !isGlibc()) ||
common.isWindows)) {
if (
!(
common.isFreeBSD ||
common.isAIX ||
(common.isLinux && !isGlibc()) ||
common.isWindows
)
) {
assert(stderr.includes('ExampleOwnerClass'), stderr);
assert(stderr.includes('CloseCallback'), stderr);
assert(stderr.includes('example_instance'), stderr);
Expand Down
46 changes: 29 additions & 17 deletions test/abort/test-http-parser-consume.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,39 @@ const { spawn } = require('child_process');
if (process.argv[2] === 'child') {
// sub-process
const server = createServer(common.mustCall((_, res) => res.end('h')));
server.listen(0, common.mustCall(() => {
const rr = get({ port: server.address().port }, common.mustCall(() => {
// This bad input (0) should abort the parser and the process
rr.parser.consume(0);
// This line should be unreachable.
assert.fail('this should be unreachable');
}));
}));
server.listen(
0,
common.mustCall(() => {
const rr = get(
{ port: server.address().port },
common.mustCall(() => {
// This bad input (0) should abort the parser and the process
rr.parser.consume(0);
// This line should be unreachable.
assert.fail('this should be unreachable');
})
);
})
);
} else {
// super-process
const child = spawn(process.execPath, [__filename, 'child']);
child.stdout.on('data', common.mustNotCall());

let stderr = '';
child.stderr.on('data', common.mustCallAtLeast((data) => {
assert(Buffer.isBuffer(data));
stderr += data.toString('utf8');
}, 1));
child.on('exit', common.mustCall((code, signal) => {
assert(stderr.includes('failed'), `stderr: ${stderr}`);
const didAbort = common.nodeProcessAborted(code, signal);
assert(didAbort, `process did not abort, code:${code} signal:${signal}`);
}));
child.stderr.on(
'data',
common.mustCallAtLeast((data) => {
assert(Buffer.isBuffer(data));
stderr += data.toString('utf8');
}, 1)
);
child.on(
'exit',
common.mustCall((code, signal) => {
assert(stderr.includes('failed'), `stderr: ${stderr}`);
const didAbort = common.nodeProcessAborted(code, signal);
assert(didAbort, `process did not abort, code:${code} signal:${signal}`);
})
);
}
21 changes: 12 additions & 9 deletions test/abort/test-process-abort-exitcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ if (process.argv[2] === 'child') {
process.abort();
} else {
const child = spawn(process.execPath, [__filename, 'child']);
child.on('exit', common.mustCall((code, signal) => {
if (common.isWindows) {
assert.strictEqual(code, 134);
assert.strictEqual(signal, null);
} else {
assert.strictEqual(code, null);
assert.strictEqual(signal, 'SIGABRT');
}
}));
child.on(
'exit',
common.mustCall((code, signal) => {
if (common.isWindows) {
assert.strictEqual(code, 134);
assert.strictEqual(signal, null);
} else {
assert.strictEqual(code, null);
assert.strictEqual(signal, 'SIGABRT');
}
})
);
}
17 changes: 10 additions & 7 deletions test/abort/test-zlib-invalid-internals-usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ const cp = require('child_process');

if (process.argv[2] === 'child') {
// This is the heart of the test.
new (process.binding('zlib').Zlib)(0).init(1, 2, 3, 4, 5);
new (process.binding('zlib')).Zlib(0).init(1, 2, 3, 4, 5);
} else {
const child = cp.spawnSync(`${process.execPath}`, [`${__filename}`, 'child']);

assert.strictEqual(child.stdout.toString(), '');
assert.ok(child.stderr.includes(
'WARNING: You are likely using a version of node-tar or npm that ' +
`is incompatible with this version of Node.js.${os.EOL}` +
'Please use either the version of npm that is bundled with Node.js, or ' +
'a version of npm (> 5.5.1 or < 5.4.0) or node-tar (> 4.0.1) that is ' +
`compatible with Node.js 9 and above.${os.EOL}`));
assert.ok(
child.stderr.includes(
'WARNING: You are likely using a version of node-tar or npm that ' +
`is incompatible with this version of Node.js.${os.EOL}` +
'Please use either the version of npm that is bundled with Node.js, or ' +
'a version of npm (> 5.5.1 or < 5.4.0) or node-tar (> 4.0.1) that is ' +
`compatible with Node.js 9 and above.${os.EOL}`
)
);
}
25 changes: 7 additions & 18 deletions test/addons-napi/test_array/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,21 @@ const array = [
13493,
9459324,
{ name: 'hello' },
[
'world',
'node',
'abi'
]
['world', 'node', 'abi']
];

assert.throws(
() => {
test_array.TestGetElement(array, array.length + 1);
},
/^Error: assertion \(\(\(uint32_t\)index < length\)\) failed: Index out of bounds!$/
);
assert.throws(() => {
test_array.TestGetElement(array, array.length + 1);
}, /^Error: assertion \(\(\(uint32_t\)index < length\)\) failed: Index out of bounds!$/);

assert.throws(
() => {
test_array.TestGetElement(array, -2);
},
/^Error: assertion \(index >= 0\) failed: Invalid index\. Expects a positive integer\.$/
);
assert.throws(() => {
test_array.TestGetElement(array, -2);
}, /^Error: assertion \(index >= 0\) failed: Invalid index\. Expects a positive integer\.$/);

array.forEach(function(element, index) {
assert.strictEqual(test_array.TestGetElement(array, index), element);
});


assert.deepStrictEqual(test_array.New(array), array);

assert(test_array.TestHasElement(array, 0));
Expand Down
68 changes: 38 additions & 30 deletions test/addons-napi/test_async/test-async-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,57 @@ const events = [];
let testId;
const initAsyncId = async_hooks.executionAsyncId();

async_hooks.createHook({
init(id, provider, triggerAsyncId, resource) {
if (provider === 'TestResource') {
testId = id;
events.push({ type: 'init', id, provider, triggerAsyncId, resource });
async_hooks
.createHook({
init(id, provider, triggerAsyncId, resource) {
if (provider === 'TestResource') {
testId = id;
events.push({ type: 'init', id, provider, triggerAsyncId, resource });
}
},
before(id) {
if (testId === id) {
events.push({ type: 'before', id });
}
},
after(id) {
if (testId === id) {
events.push({ type: 'after', id });
}
},
destroy(id) {
if (testId === id) {
events.push({ type: 'destroy', id });
}
}
},
before(id) {
if (testId === id) {
events.push({ type: 'before', id });
}
},
after(id) {
if (testId === id) {
events.push({ type: 'after', id });
}
},
destroy(id) {
if (testId === id) {
events.push({ type: 'destroy', id });
}
}
}).enable();
})
.enable();

const resource = { foo: 'foo' };

events.push({ type: 'start' });
test_async.Test(5, resource, common.mustCall(function(err, val) {
assert.strictEqual(err, null);
assert.strictEqual(val, 10);
events.push({ type: 'complete' });
process.nextTick(common.mustCall());
}));
test_async.Test(
5,
resource,
common.mustCall(function(err, val) {
assert.strictEqual(err, null);
assert.strictEqual(val, 10);
events.push({ type: 'complete' });
process.nextTick(common.mustCall());
})
);
events.push({ type: 'scheduled' });

process.on('exit', () => {
assert.deepStrictEqual(events, [
{ type: 'start' },
{ type: 'init',
{
type: 'init',
id: testId,
provider: 'TestResource',
triggerAsyncId: initAsyncId,
resource },
resource
},
{ type: 'scheduled' },
{ type: 'before', id: testId },
{ type: 'complete' },
Expand Down
Loading

0 comments on commit 517c95c

Please sign in to comment.