Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
fix: Work around inconsistent handling of strict directive
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Krems committed Mar 14, 2017
1 parent 2b93173 commit b4d5ee2
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 11 deletions.
1 change: 0 additions & 1 deletion examples/alive.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';
let x = 0;
function heartbeat() {
++x;
Expand Down
1 change: 0 additions & 1 deletion examples/backtrace.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';
const { exports: moduleScoped } = module;

function topFn(a, b = false) {
Expand Down
1 change: 0 additions & 1 deletion examples/cjs/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';
const { add } = require('./other');

const sum = add(40, 2);
Expand Down
1 change: 0 additions & 1 deletion examples/cjs/other.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';
exports.add = function add(a, b) {
return a + b;
};
1 change: 0 additions & 1 deletion examples/exceptions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';
let error = null;
try {
throw new Error('Caught');
Expand Down
1 change: 0 additions & 1 deletion examples/three-lines.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';
let x = 1;
x = x + 1;
module.exports = x;
2 changes: 2 additions & 0 deletions examples/use-strict.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
'use strict';
console.log('first real line');
4 changes: 2 additions & 2 deletions test/cli/backtrace.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ test('display and navigate backtrace', (t) => {
.then(() => cli.stepCommand('c'))
.then(() => cli.command('bt'))
.then(() => {
t.match(cli.output, `#0 topFn ${script}:8:2`);
t.match(cli.output, `#0 topFn ${script}:7:2`);
})
.then(() => cli.command('backtrace'))
.then(() => {
t.match(cli.output, `#0 topFn ${script}:8:2`);
t.match(cli.output, `#0 topFn ${script}:7:2`);
})
.then(() => cli.quit())
.then(null, onFatal);
Expand Down
6 changes: 3 additions & 3 deletions test/cli/exceptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ test('break on (uncaught) exceptions', (t) => {
.then(() => cli.command('breakOnException'))
.then(() => cli.stepCommand('c'))
.then(() => {
t.match(cli.output, `exception in ${script}:4`);
t.match(cli.output, `exception in ${script}:3`);
})
.then(() => cli.stepCommand('c'))
.then(() => {
t.match(cli.output, `exception in ${script}:10`);
t.match(cli.output, `exception in ${script}:9`);
})

// Next run: With `breakOnUncaught` it only pauses on the 2nd exception
Expand All @@ -46,7 +46,7 @@ test('break on (uncaught) exceptions', (t) => {
})
.then(() => cli.stepCommand('c'))
.then(() => {
t.match(cli.output, `exception in ${script}:10`);
t.match(cli.output, `exception in ${script}:9`);
})

// Next run: Back to the initial state! It should die again.
Expand Down
27 changes: 27 additions & 0 deletions test/cli/use-strict.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';
const Path = require('path');

const { test } = require('tap');

const startCLI = require('./start-cli');

test('for whiles that starts with strict directive', (t) => {
const script = Path.join('examples', 'use-strict.js');
const cli = startCLI([script]);

function onFatal(error) {
cli.quit();
throw error;
}

return cli.waitFor(/break/)
.then(() => cli.waitForPrompt())
.then(() => {
t.match(
cli.output,
/break in [^:]+:(?:1|2)[^\d]/,
'pauses either on strict directive or first "real" line');
})
.then(() => cli.quit())
.then(null, onFatal);
});

0 comments on commit b4d5ee2

Please sign in to comment.