Skip to content

Commit

Permalink
Fix indendation + add editorconfig file
Browse files Browse the repository at this point in the history
  • Loading branch information
christianvuerings committed Nov 7, 2024
1 parent a5a0874 commit e1b1e25
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 75 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
148 changes: 74 additions & 74 deletions main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,83 +10,83 @@ describe('node-memwatch', () => {
expect(memwatch.HeapDiff).toBeDefined();
});

describe('.gc()', () => {
it('causes a stats() event to be emitted', () => {
return new Promise((resolve) => {
memwatch.once('stats', (s) => {
expect(typeof s).toBe('object');
resolve();
});
memwatch.gc();
});
});
});
describe('.gc()', () => {
it('causes a stats() event to be emitted', () => {
return new Promise((resolve) => {
memwatch.once('stats', (s) => {
expect(typeof s).toBe('object');
resolve();
});
memwatch.gc();
});
});
});

describe('HeapDiff', () => {
it('detects allocations', () => {
function LeakingClass() {};
const arr = [];
const hd = new memwatch.HeapDiff();
for (let i = 0; i < 100; i++) arr.push(new LeakingClass());
const diff = hd.end();
expect(Array.isArray(diff.change.details)).toBe(true);
// find the LeakingClass elem
let leakingReport;
diff.change.details.forEach((d) => {
if (d.what === 'LeakingClass')
leakingReport = d;
});
expect(leakingReport).toBeDefined();
expect(leakingReport['+'] - leakingReport['-']).toBeGreaterThan(0);
});
describe('HeapDiff', () => {
it('detects allocations', () => {
function LeakingClass() {};
const arr = [];
const hd = new memwatch.HeapDiff();
for (let i = 0; i < 100; i++) arr.push(new LeakingClass());
const diff = hd.end();
expect(Array.isArray(diff.change.details)).toBe(true);
// find the LeakingClass elem
let leakingReport;
diff.change.details.forEach((d) => {
if (d.what === 'LeakingClass')
leakingReport = d;
});
expect(leakingReport).toBeDefined();
expect(leakingReport['+'] - leakingReport['-']).toBeGreaterThan(0);
});

it('has the correct output format', () => {
function LeakingClass() {};
const arr = [];
const hd = new memwatch.HeapDiff();
for (let i = 0; i < 100; i++) arr.push(new LeakingClass());
expect(hd.end()).toEqual(
expect.objectContaining({
after: expect.objectContaining({
nodes: expect.any(Number),
size: expect.any(String),
size_bytes: expect.any(Number),
}),
before: expect.objectContaining({
nodes: expect.any(Number),
size: expect.any(String),
size_bytes: expect.any(Number),
}),
change: expect.objectContaining({
allocated_nodes: expect.any(Number),
details: expect.arrayContaining([
expect.objectContaining({
'+': expect.any(Number),
'-': expect.any(Number),
size: expect.any(String),
size_bytes: expect.any(Number),
what: expect.any(String),
}),
]),
freed_nodes: expect.any(Number),
size: expect.any(String),
size_bytes: expect.any(Number),
}),
})
)
});
it('has the correct output format', () => {
function LeakingClass() {};
const arr = [];
const hd = new memwatch.HeapDiff();
for (let i = 0; i < 100; i++) arr.push(new LeakingClass());
expect(hd.end()).toEqual(
expect.objectContaining({
after: expect.objectContaining({
nodes: expect.any(Number),
size: expect.any(String),
size_bytes: expect.any(Number),
}),
before: expect.objectContaining({
nodes: expect.any(Number),
size: expect.any(String),
size_bytes: expect.any(Number),
}),
change: expect.objectContaining({
allocated_nodes: expect.any(Number),
details: expect.arrayContaining([
expect.objectContaining({
'+': expect.any(Number),
'-': expect.any(Number),
size: expect.any(String),
size_bytes: expect.any(Number),
what: expect.any(String),
}),
]),
freed_nodes: expect.any(Number),
size: expect.any(String),
size_bytes: expect.any(Number),
}),
})
)
});

it('double end should throw', () => {
const hd = new memwatch.HeapDiff();
expect(() => hd.end()).not.toThrow();
expect(() => hd.end()).toThrow();
});
it('double end should throw', () => {
const hd = new memwatch.HeapDiff();
expect(() => hd.end()).not.toThrow();
expect(() => hd.end()).toThrow();
});

it('improper HeapDiff allocation should throw an exception', () => {
// equivalent to "new require('memwatch').HeapDiff()"
// see issue #30
expect(() => new (memwatch.HeapDiff())).toThrow();
});
});
it('improper HeapDiff allocation should throw an exception', () => {
// equivalent to "new require('memwatch').HeapDiff()"
// see issue #30
expect(() => new (memwatch.HeapDiff())).toThrow();
});
});
});

2 changes: 1 addition & 1 deletion src/memwatch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ NAN_GC_CALLBACK(memwatch::after_gc) {
s_stats.gcProcessWeakCallbacksTime += gcTime;
return;

case kGCTypeMinorMarkCompact:
case kGCTypeMinorMarkCompact:
case kGCTypeMarkSweepCompact:
case kGCTypeAll:
break;
Expand Down

0 comments on commit e1b1e25

Please sign in to comment.