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

ESLint for test files #320

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
"env": {
"node": true,
"commonjs": true,
"es6": true
},
"extends": ["eslint:recommended"],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
}
};
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"codecov-upload-js": "codecov --disable=gcov --file=coverage-js.lcov",
"codecov-upload": "npm run codecov-upload-cc && npm run codecov-upload-js",
"linter": "node scripts/linter.js",
"format": "npx clang-format -i src/*"
"format": "npx clang-format -i src/*",
"lint-test": "(npx eslint test{,/**}/*.js && echo 'No problems found') || echo 'Lint failed for some files'"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -54,9 +55,10 @@
},
"homepage": "https://github.com/nodejs/llnode#readme",
"devDependencies": {
"clang-format": "1.2.4",
"codecov": "^3.1.0",
"eslint": "^6.5.1",
"nyc": "^13.1.0",
"clang-format": "1.2.4",
"tape": "^4.4.0"
},
"nyc": {
Expand All @@ -73,4 +75,4 @@
"bindings": "^1.3.0",
"node-addon-api": "^1.1.0"
}
}
}
16 changes: 8 additions & 8 deletions test/common.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const fs = require('fs');
const os = require('os');
const path = require('path');
const util = require('util');
Expand Down Expand Up @@ -48,7 +47,7 @@ function SessionOutput(session, stream, timeout) {
stream.on('data', (data) => {
buf += data;

for (;;) {
for (; ;) {
let index = buf.indexOf('\n');

if (index === -1)
Expand Down Expand Up @@ -114,7 +113,7 @@ SessionOutput.prototype.wait = function wait(regexp, callback, allLines) {
}

let done = false;
const check = setTimeout(() => {
setTimeout(() => {
if (done)
return;

Expand Down Expand Up @@ -229,7 +228,8 @@ function saveCoreLLDB(scenario, core, cb) {
function spawnWithTimeout(cmd, cb) {
const proc = spawn(cmd, {
shell: true,
stdio: ['pipe', 'pipe', 'pipe'] });
stdio: ['pipe', 'pipe', 'pipe']
});
const stdout = new SessionOutput(null, proc.stdout, exports.saveCoreTimeout);
const stderr = new SessionOutput(null, proc.stderr, exports.saveCoreTimeout);
stdout.on('line', (line) => { debug('[stdout]', line); });
Expand All @@ -240,16 +240,16 @@ function spawnWithTimeout(cmd, cb) {
proc.kill();
}, exports.saveCoreTimeout);

proc.on('exit', (status) => {
proc.on('exit', () => {
clearTimeout(timeout);
cb(null);
});
}

function saveCoreLinux(executable, scenario, core, cb) {
const cmd = `ulimit -c unlimited && ${executable} ` +
`--abort_on_uncaught_exception --expose_externalize_string ` +
`${path.join(exports.fixturesDir, scenario)}; `;
`--abort_on_uncaught_exception --expose_externalize_string ` +
`${path.join(exports.fixturesDir, scenario)}; `;
spawnWithTimeout(cmd, () => {
// FIXME (mmarchini): Should also handle different core system settings.
spawnWithTimeout(`mv ./core ${core}`, cb);
Expand Down Expand Up @@ -314,7 +314,7 @@ Session.prototype.hasSymbol = function hasSymbol(symbol, callback) {

let pattern = new RegExp(symbol);
this.linesUntil(versionMark, (err, lines) => {
if(pattern.test(lines.join('\n'))) {
if (pattern.test(lines.join('\n'))) {
callback(err, true);
} else {
return callback(err, false);
Expand Down
4 changes: 1 addition & 3 deletions test/fixtures/frame-scenario.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Note: top-level 'use strict' intentionally omitted.
const common = require('../common');

function crasher(unused) {
function crasher() {
'use strict';
process.abort(); // Creates an exit frame.
return this; // Force definition of |this|.
Expand Down
22 changes: 6 additions & 16 deletions test/fixtures/inspect-scenario.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

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

const zlib = require('zlib');

let outerVar = 'outer variable';
Expand Down Expand Up @@ -36,19 +34,18 @@ function closure() {
c.hashmap['some-key'] = 42;
c.hashmap['other-key'] = 'ohai';
c.hashmap['cons-string'] =
'this could be a bit smaller, but v8 wants big str.';
'this could be a bit smaller, but v8 wants big str.';
c.hashmap['cons-string'] += c.hashmap['cons-string'];
c.hashmap['internalized-string'] = 'foobar';
// This thin string points to the previous 'foobar'.
c.hashmap['thin-string'] = makeThin('foo', 'bar');
// Create an externalized string and slice it.
c.hashmap['externalized-string'] =
'string that will be externalized and sliced';
externalizeString(c.hashmap['externalized-string']);
'string that will be externalized and sliced';
// Sliced strings need to be longer that SlicedString::kMinLength
// which seems to be 13 so our string is 26.
c.hashmap['sliced-externalized-string'] =
c.hashmap['externalized-string'].substring(10,36);
c.hashmap['externalized-string'].substring(10, 36);

c.hashmap['array'] = [true, 1, undefined, null, 'test', Class];
c.hashmap['long-array'] = new Array(20).fill(5);
Expand All @@ -70,12 +67,12 @@ function closure() {
c.hashmap[0] = null;
c.hashmap[4] = undefined;
c.hashmap[23] = /regexp/;
c.hashmap[25] = (a,b)=>{a+b};
c.hashmap[25] = (a, b) => { a + b };
c.hashmap[oneSymbol] = 42;

let scopedVar = 'scoped value';
let scopedAPI = zlib.createDeflate()._handle;
let scopedArray = [ 0, scopedAPI ];
let scopedArray = [0, scopedAPI];

c.hashmap['date_1'] = new Date('2000-01-01');
c.hashmap['date_2'] = new Date(1);
Expand All @@ -90,15 +87,8 @@ function closure() {
this.name = "Class B";
}

function Class_C(class_b_array) {
this.arr = class_b_array;
this.my_class_c = "My Class C";
}

const arr = new Array();
for(let i=0; i < 10; i++) arr.push(new Class_B());

let classC = new Class_C(arr);
for (let i = 0; i < 10; i++) arr.push(new Class_B());

c.method();
}
Expand Down
20 changes: 2 additions & 18 deletions test/fixtures/scan-scenario.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
'use strict';

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

const zlib = require('zlib');

let outerVar = 'outer variable';

exports.holder = {};

function makeThin(a, b) {
var str = a + b;
var obj = {};
obj[str]; // Turn the cons string into a thin string.
return str;
}

function closure() {

function Class() {
Expand All @@ -34,7 +25,7 @@ function closure() {

let scopedVar = 'scoped value';
let scopedAPI = zlib.createDeflate()._handle;
let scopedArray = [ 0, scopedAPI ];
let scopedArray = [0, scopedAPI];

exports.holder = scopedAPI;

Expand All @@ -46,15 +37,8 @@ function closure() {
this.my_class_b = "Class B";
}

function Class_C(class_b_array) {
this.arr = class_b_array;
this.my_class_c = "My Class C";
}

const arr = new Array();
for(let i=0; i < 10; i++) arr.push(new Class_B());

let classC = new Class_C(arr);
for (let i = 0; i < 10; i++) arr.push(new Class_B());

c.method();
}
Expand Down
8 changes: 3 additions & 5 deletions test/fixtures/stack-scenario.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
'use strict';

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

function first() {
second('second args', 1);
}

function second(arg1, arg2) {
function second() {
third('third args', 1, { a: 1 });
}

function third(arg1, arg2, arg3) {
function third() {
const c = new Class();

c.method('method args', 1.23, null);
Expand All @@ -19,7 +17,7 @@ function third(arg1, arg2, arg3) {
function Class() {
}

Class.prototype.method = function method(arg1, arg2, arg3) {
Class.prototype.method = function method() {
throw new Error('Uncaught');
};

Expand Down
8 changes: 3 additions & 5 deletions test/fixtures/workqueue-scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ const http = require('http')
var fs = require('fs');

// Creates a Timer to be inspected with getactivehandles
setInterval(() => {}, 500);
setInterval(() => { }, 500);

// Creates a TCP to be inspected with getactivehandles
const server = http.createServer((req, res) => { res.end('test'); });
server.listen(4321, (err) => {});
server.listen(4321, () => { });

// Creates a FSReqWrap to be inspected with getactivehandles
fs.readFile('invalidFile', (err, data) => {});

uncaughtException();
fs.readFile('invalidFile', () => { });
20 changes: 10 additions & 10 deletions test/plugin/frame-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const tape = require('tape');
const common = require('../common');

const sourceCode = [
"10 function eyecatcher() {",
"11 crasher(); // # args < # formal parameters inserts an adaptor frame.",
"12 return this; // Force definition of |this|.",
"13 }",
"10 function eyecatcher() {",
"11 crasher(); // # args < # formal parameters inserts an adaptor frame.",
"12 return this; // Force definition of |this|.",
"13 }",
];
const lastLine = new RegExp(sourceCode[sourceCode.length - 1]);

Expand All @@ -20,35 +20,35 @@ function fatalError(t, sess, err) {

function testFrameList(t, sess, frameNumber) {
sess.send(`frame select ${frameNumber}`);
sess.linesUntil(/frame/, (err, lines) => {
sess.linesUntil(/frame/, (err) => {
if (err) {
return fatalError(t, sess, err);
}
sess.send('v8 source list');

sess.linesUntil(/v8 source list/, (err, lines) => {
sess.linesUntil(/v8 source list/, () => {
sess.linesUntil(lastLine, (err, lines) => {
if (err) {
return fatalError(t, sess, err);
}
t.equal(lines.length, sourceCode.length,
`v8 source list correct size`);
`v8 source list correct size`);
for (let i = 0; i < lines.length; i++) {
t.equal(lines[i].trim(), sourceCode[i], `v8 source list #${i}`);
}

sess.send('v8 source list -l 2');

sess.linesUntil(/v8 source list/, (err, lines) => {
sess.linesUntil(/v8 source list/, () => {
sess.linesUntil(lastLine, (err, lines) => {
if (err) {
return fatalError(t, sess, err);
}
t.equal(lines.length, sourceCode.length - 1,
`v8 source list -l 2 correct size`);
`v8 source list -l 2 correct size`);
for (let i = 0; i < lines.length; i++) {
t.equal(lines[i].trim(), sourceCode[i + 1],
`v8 source list -l 2 #${i}`);
`v8 source list -l 2 #${i}`);
}

sess.quit();
Expand Down
2 changes: 1 addition & 1 deletion test/plugin/workqueue-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ tape('v8 workqueue commands', (t) => {
});

// Check if current node version support these commands.
sess.waitError(/error: Couldn't get node's Environment/, (err, line) => {
sess.waitError(/error: Couldn't get node's Environment/, (err) => {
if (err) {
testWorkqueueCommands(t, sess);
} else {
Expand Down