Skip to content

Commit a681ecf

Browse files
committed
Ensure 'this' in test implementations is null
We shouldn't expose the test instance through 'this'.
1 parent b30e6a6 commit a681ecf

File tree

7 files changed

+21
-14
lines changed

7 files changed

+21
-14
lines changed

lib/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ class Test {
312312
try {
313313
return {
314314
ok: true,
315-
retval: this.fn(this.createExecutionContext())
315+
retval: this.fn.call(null, this.createExecutionContext())
316316
};
317317
} catch (err) {
318318
return {

test/reporters/mini.regular.log

+3-3
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ stderr
225225
https://github.com/avajs/ava#throwsfunctionpromise-error-message
226226

227227
fn (test.js:35:9)
228-
Test.t [as fn] (test.js:37:11)
228+
t (test.js:37:11)
229229

230230

231231

@@ -254,7 +254,7 @@ stderr
254254
https://github.com/avajs/ava#throwsfunctionpromise-error-message
255255

256256
fn (test.js:42:9)
257-
Test.t [as fn] (test.js:44:14)
257+
t (test.js:44:14)
258258

259259

260260

@@ -275,7 +275,7 @@ stderr
275275

276276
Unhandled rejection in test/fixture/report/regular/unhandled-rejection.js
277277
Error: Can't catch me
278-
Test.t [as fn] (unhandled-rejection.js:4:17)
278+
t (unhandled-rejection.js:4:17)
279279

280280
Unhandled rejection in test/fixture/report/regular/unhandled-rejection.js
281281
Threw non-error: {"message":"null"}

test/reporters/tap.failfast.log

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ not ok 1 - a › fails
66
name: AssertionError
77
message: Test failed via `t.fail()`
88
assertion: fail
9-
at: 'Test.t [as fn] (a.js:3:22)'
9+
at: 't (a.js:3:22)'
1010
...
1111
---tty-stream-chunk-separator
1212

test/reporters/tap.failfast2.log

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ not ok 1 - a › fails
66
name: AssertionError
77
message: Test failed via `t.fail()`
88
assertion: fail
9-
at: 'Test.t [as fn] (a.js:3:22)'
9+
at: 't (a.js:3:22)'
1010
...
1111
---tty-stream-chunk-separator
1212

test/reporters/tap.regular.log

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ok 4 - unhandled-rejection › unhandled non-error rejection
2020
not ok 5 - Can't catch me
2121
---
2222
name: Error
23-
at: 'Test.t [as fn] (unhandled-rejection.js:4:17)'
23+
at: 't (unhandled-rejection.js:4:17)'
2424
...
2525
---tty-stream-chunk-separator
2626
# null
@@ -58,7 +58,7 @@ not ok 12 - test › fails
5858
name: AssertionError
5959
message: Test failed via `t.fail()`
6060
assertion: fail
61-
at: 'Test.t [as fn] (test.js:12:22)'
61+
at: 't (test.js:12:22)'
6262
...
6363
---tty-stream-chunk-separator
6464
# test › known failure
@@ -81,7 +81,7 @@ not ok 15 - test › logs
8181
name: AssertionError
8282
message: Test failed via `t.fail()`
8383
assertion: fail
84-
at: 'Test.t [as fn] (test.js:21:4)'
84+
at: 't (test.js:21:4)'
8585
...
8686
---tty-stream-chunk-separator
8787
# test › formatted
@@ -93,7 +93,7 @@ not ok 16 - test › formatted
9393
'Difference:': |-
9494
- 'foo'
9595
+ 'bar'
96-
at: 'Test.t [as fn] (test.js:25:4)'
96+
at: 't (test.js:25:4)'
9797
...
9898
---tty-stream-chunk-separator
9999
# test › power-assert
@@ -104,7 +104,7 @@ not ok 17 - test › power-assert
104104
operator: '!'
105105
values:
106106
'Value is not falsy:': '''bar'''
107-
at: 'Test.t [as fn] (test.js:30:4)'
107+
at: 't (test.js:30:4)'
108108
...
109109
---tty-stream-chunk-separator
110110
# test › bad throws

test/reporters/verbose.regular.log

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
---tty-stream-chunk-separator
1616
Unhandled rejection in test/fixture/report/regular/unhandled-rejection.js
1717
Error: Can't catch me
18-
Test.t [as fn] (unhandled-rejection.js:4:17)
18+
t (unhandled-rejection.js:4:17)
1919

2020

2121

@@ -167,7 +167,7 @@ stderr
167167
https://github.com/avajs/ava#throwsfunctionpromise-error-message
168168

169169
fn (test.js:35:9)
170-
Test.t [as fn] (test.js:37:11)
170+
t (test.js:37:11)
171171

172172

173173

@@ -196,7 +196,7 @@ stderr
196196
https://github.com/avajs/ava#throwsfunctionpromise-error-message
197197

198198
fn (test.js:42:9)
199-
Test.t [as fn] (test.js:44:14)
199+
t (test.js:44:14)
200200

201201

202202

test/test.js

+7
Original file line numberDiff line numberDiff line change
@@ -758,3 +758,10 @@ test('snapshot assertion cannot be skipped when updating snapshots', t => {
758758
t.is(result.error.message, 'Snapshot assertions cannot be skipped when updating snapshots');
759759
});
760760
});
761+
762+
test('implementation runs with null scope', t => {
763+
return ava(function (a) {
764+
a.pass();
765+
t.is(this, null);
766+
}).run();
767+
});

0 commit comments

Comments
 (0)