Skip to content

Commit

Permalink
fix stack location error
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurent RENARD authored and Laurent RENARD committed Oct 24, 2019
1 parent 8f64199 commit c53a2e9
Show file tree
Hide file tree
Showing 28 changed files with 56 additions and 55 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ test/dist
benchmarks
dist
src/*.js
sample.html
6 changes: 3 additions & 3 deletions benchmarks/ava/test/test1.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

const test = require('ava');
for (let i = 0; i < 10; i++) {
for (let i = 0; i < 8; i++) {
test('test ' + i, async function (assert) {
await new Promise(resolve => {
setTimeout(()=>resolve(),100);
setTimeout(()=>resolve(),50);
});
assert.truthy(Math.random() * 100 > 5);
assert.truthy(Math.random() * 100 > 3);
});
}
6 changes: 3 additions & 3 deletions benchmarks/jest/test/test1.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

describe('add', function () {
for (let i = 0; i < 10; i++) {
for (let i = 0; i < 8; i++) {
it('should test',async function () {
await new Promise(resolve => {
setTimeout(()=>resolve(),100);
setTimeout(()=>resolve(),50);
});
expect(Math.random() * 100 > 5).toBeTruthy();
expect(Math.random() * 100 > 3).toBeTruthy();
});
}
});
6 changes: 3 additions & 3 deletions benchmarks/mocha/test/test1.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

const assert = require('assert');
describe('test file', function() {
for(let i=0; i < 10;i++){
for(let i=0; i < 8;i++){
it('test ' + i, function(done) {
setTimeout(()=>{
assert.ok(Math.random() * 100 > 5);
assert.ok(Math.random() * 100 > 3);
done();
},100);
},50);
});
}
});
6 changes: 3 additions & 3 deletions benchmarks/tape/test/test1.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

const test = require('tape');
for (let i = 0; i < 10; i++) {
for (let i = 0; i < 8; i++) {
test('test ' + i, function (assert) {
setTimeout(()=>{
assert.ok(Math.random() * 100 > 5);
assert.ok(Math.random() * 100 > 3);
assert.end();
},100);
},50);
});
}
3 changes: 2 additions & 1 deletion benchmarks/zora/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

const {test} = require('../../dist/bundle/index.js');
const path = require('path');
const fs = require('fs');
const tests = fs.readdirSync(path.join(process.cwd(),'./benchmarks/zora/test'));
for (let f of tests){
require(path.join(process.cwd(),'./benchmarks/zora/test/',f));
test(f,require(path.join(process.cwd(),'./benchmarks/zora/test/',f)));
}
10 changes: 5 additions & 5 deletions benchmarks/zora/test/test1.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

const {test} = require('../../../dist/bundle/index.js');
for (let i = 0; i < 10; i++) {
module.exports =(({test}) => {
for (let i = 0; i < 8; i++) {
test('test ' + i, async function (assert) {
await new Promise(resolve => {
setTimeout(()=>resolve(),100);
setTimeout(()=>resolve(),50);
});
assert.ok(Math.random() * 100 > 5);
assert.ok(Math.random() * 100 > 3);
});
}
}});
22 changes: 11 additions & 11 deletions scripts/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ const fs = require('fs');
const path = require('path');

const filesCount = 12;
const testCount = 10;
const waitTime = 100;
const testCount = 8;
const waitTime = 50;

const zoraCode = `
const {test} = require('../../../dist/bundle/index.js');
module.exports =(({test}) => {
for (let i = 0; i < ${testCount}; i++) {
test('test ' + i, async function (assert) {
await new Promise(resolve => {
setTimeout(()=>resolve(),${waitTime});
});
assert.ok(Math.random() * 100 > 5);
assert.ok(Math.random() * 100 > 3);
});
}
}});
`;

const avaCode = `
Expand All @@ -24,7 +24,7 @@ for (let i = 0; i < ${testCount}; i++) {
await new Promise(resolve => {
setTimeout(()=>resolve(),${waitTime});
});
assert.truthy(Math.random() * 100 > 5);
assert.truthy(Math.random() * 100 > 3);
});
}
`;
Expand All @@ -35,7 +35,7 @@ describe('test file', function() {
for(let i=0; i < ${testCount};i++){
it('test ' + i, function(done) {
setTimeout(()=>{
assert.ok(Math.random() * 100 > 5);
assert.ok(Math.random() * 100 > 3);
done();
},${waitTime});
});
Expand All @@ -48,7 +48,7 @@ const test = require('tape');
for (let i = 0; i < ${testCount}; i++) {
test('test ' + i, function (assert) {
setTimeout(()=>{
assert.ok(Math.random() * 100 > 5);
assert.ok(Math.random() * 100 > 3);
assert.end();
},${waitTime});
});
Expand All @@ -62,7 +62,7 @@ describe('add', function () {
await new Promise(resolve => {
setTimeout(()=>resolve(),${waitTime});
});
expect(Math.random() * 100 > 5).toBeTruthy();
expect(Math.random() * 100 > 3).toBeTruthy();
});
}
});
Expand All @@ -77,15 +77,15 @@ for (let f of tests){
}
`;
const zoraIndex = `
const {test} = require('../../dist/bundle/index.js');
const path = require('path');
const fs = require('fs');
const tests = fs.readdirSync(path.join(process.cwd(),'./benchmarks/zora/test'));
for (let f of tests){
require(path.join(process.cwd(),'./benchmarks/zora/test/',f));
test(f,require(path.join(process.cwd(),'./benchmarks/zora/test/',f)));
}
`;


for (let i = 1; i <= filesCount; i++) {
const zoraPath = path.join(process.cwd(), '/benchmarks/zora/test/', 'test' + i + '.js');
const avaPath = path.join(process.cwd(), '/benchmarks/ava/test/', 'test' + i + '.js');
Expand Down
7 changes: 3 additions & 4 deletions src/assertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ export const isAssertionResult = (result: Test | AssertionResult): result is Ass
};

const specFnRegexp = /zora_spec_fn/;
const nodeInternal = /node_modules\/.*|\(internal\/.*/;

const getAssertionLocation = (): string => {
const err = new Error();
const stack = (err.stack || '')
.split('\n')
.filter(l => !nodeInternal.test(l) && l !== '');
.filter(l => l !== '');
const userLandIndex = stack.findIndex(l => specFnRegexp.test(l));
return (userLandIndex >= 1 ?
stack[userLandIndex - 1] : (stack[stack.length - 1] || 'N/A'))
const stackline = userLandIndex >= 1 ? stack[userLandIndex - 1] : (stack[stack.length - 1] || 'N/A');
return stackline
.trim()
.replace(/^at|^@/, '');
};
Expand Down
2 changes: 1 addition & 1 deletion test/samples/cases/async.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {test} from '../../../src/index.js';
import {test} from '../../../dist/bundle/module.js';

const wait = time => new Promise(resolve => {
setTimeout(() => resolve(), time);
Expand Down
2 changes: 1 addition & 1 deletion test/samples/cases/bailout.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {test} from '../../../src/index.js';
import {test} from '../../../dist/bundle/module.js';

test('will not go to the end', t => {
t.ok(true, 'okay');
Expand Down
2 changes: 1 addition & 1 deletion test/samples/cases/bailout_nested.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {test} from '../../../src/index.js';
import {test} from '../../../dist/bundle/module.js';

test('will not go to the end', t => {
t.ok(true, 'okay');
Expand Down
2 changes: 1 addition & 1 deletion test/samples/cases/check_flush.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {test} from '../../../src/index.js';
import {test} from '../../../dist/bundle/module.js';

const wait = time => new Promise(resolve => {
setTimeout(() => resolve(), time);
Expand Down
2 changes: 1 addition & 1 deletion test/samples/cases/custom_assertion.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {test} from '../../../src/index.js';
import {test} from '../../../dist/bundle/module.js';

const customAssert = spec => t => {
return spec(Object.assign(t, {
Expand Down
2 changes: 1 addition & 1 deletion test/samples/cases/failing.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {test} from '../../../src/index.js';
import {test} from '../../../dist/bundle/module.js';

test('tester 1', t => {
t.ok(true, 'assert1');
Expand Down
2 changes: 1 addition & 1 deletion test/samples/cases/failing_nested.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {test} from '../../../src/index.js';
import {test} from '../../../dist/bundle/module.js';

test('tester 1', t => {
t.ok(true, 'assert1');
Expand Down
2 changes: 1 addition & 1 deletion test/samples/cases/mixed_root_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ok, test, eq} from '../../../src/index.js';
import {eq, ok, test} from '../../../dist/bundle/module.js';

ok(true, 'true is truthy');

Expand Down
2 changes: 1 addition & 1 deletion test/samples/cases/nested.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {test} from '../../../src/index.js';
import {test} from '../../../dist/bundle/module.js';

test('tester 1', t => {

Expand Down
2 changes: 1 addition & 1 deletion test/samples/cases/nested_async.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {test} from '../../../src/index.js';
import {test} from '../../../dist/bundle/module.js';

const wait = time => new Promise(resolve => {
setTimeout(() => resolve(), time);
Expand Down
2 changes: 1 addition & 1 deletion test/samples/cases/no_only_mode.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {test, only} from '../../../src/index.js';
import {test, only} from '../../../dist/bundle/module.js';

test('should not run', t => {
t.fail('I should not run ');
Expand Down
2 changes: 1 addition & 1 deletion test/samples/cases/no_only_mode_nested.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {test, only} from '../../../src/index.js';
import {test, only} from '../../../dist/bundle/module.js';

test('should not run', t => {
t.fail('I should not run ');
Expand Down
2 changes: 1 addition & 1 deletion test/samples/cases/only.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {test, only} from '../../../src/index.js';
import {only, test} from '../../../dist/bundle/module.js';

test('should not run', t => {
t.fail('I should not run ');
Expand Down
2 changes: 1 addition & 1 deletion test/samples/cases/only_nested.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {test, only} from '../../../src/index.js';
import {test, only} from '../../../dist/bundle/module.js';

test('should not run', t => {
t.fail('I should not run ');
Expand Down
4 changes: 2 additions & 2 deletions test/samples/cases/root_level_failing.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ok ,eq} from '../../../src/index.js';
import {eq, ok} from '../../../dist/bundle/module.js';

ok(true, 'true is truthy');
eq([],[2],'unhappy arrays');
eq([], [2], 'unhappy arrays');
eq({foo: 'bar'}, {foo: 'bar'}, 'foo bar');
2 changes: 1 addition & 1 deletion test/samples/cases/root_level_only.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ok, eq} from '../../../src/index.js';
import {eq, ok} from '../../../dist/bundle/module.js';

ok(true, 'true is truthy');
eq({foo: 'bar'}, {foo: 'bar'}, 'foo bar');
2 changes: 1 addition & 1 deletion test/samples/cases/simple.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {test} from '../../../src/index.js';
import {test} from '../../../dist/bundle/module.js';

test('tester 1', t => {
t.ok(true, 'assert1');
Expand Down
2 changes: 1 addition & 1 deletion test/samples/cases/skip.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {test, ok, skip} from '../../../src/index.js';
import {test, ok, skip} from '../../../dist/bundle/module.js';

ok(true, 'hey hey');
ok(true, 'hey hey bis');
Expand Down
6 changes: 3 additions & 3 deletions test/samples/cases/symbol.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {test} from '../../../src/index.js';
import {test} from '../../../dist/bundle/module.js';

test('symbol tester 1', t => {
t.equal(Symbol('foo'),Symbol('bar'),'Symbol foo should equal Symbol bar');
t.equal({symbol: Symbol('foo')},{symbol:Symbol('bar')}, 'Property Symbol foo should equal Symbol bar')
t.equal(Symbol('foo'), Symbol('bar'), 'Symbol foo should equal Symbol bar');
t.equal({symbol: Symbol('foo')}, {symbol: Symbol('bar')}, 'Property Symbol foo should equal Symbol bar');
});

0 comments on commit c53a2e9

Please sign in to comment.