Skip to content

Commit 262911f

Browse files
committed
ES2015ify #1113
1 parent ee65b6d commit 262911f

File tree

7 files changed

+88
-91
lines changed

7 files changed

+88
-91
lines changed

lib/assert.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'use strict';
2-
var util = require('util');
3-
var assert = require('core-assert');
4-
var deepEqual = require('lodash.isequal');
5-
var observableToPromise = require('observable-to-promise');
6-
var indentString = require('indent-string');
7-
var isObservable = require('is-observable');
8-
var isPromise = require('is-promise');
9-
var jestSnapshot = require('jest-snapshot');
10-
var snapshotState = require('./snapshot-state');
2+
const util = require('util');
3+
const assert = require('core-assert');
4+
const deepEqual = require('lodash.isequal');
5+
const observableToPromise = require('observable-to-promise');
6+
const indentString = require('indent-string');
7+
const isObservable = require('is-observable');
8+
const isPromise = require('is-promise');
9+
const jestSnapshot = require('jest-snapshot');
10+
const snapshotState = require('./snapshot-state');
1111

1212
const x = module.exports;
1313
const noop = () => {};
@@ -153,23 +153,25 @@ x.ifError = (err, msg) => {
153153

154154
x._snapshot = function (tree, optionalMessage, match, snapshotStateGetter) {
155155
// set defaults - this allows tests to mock deps easily
156-
var toMatchSnapshot = match || jestSnapshot.toMatchSnapshot;
157-
var getState = snapshotStateGetter || snapshotState.get;
156+
const toMatchSnapshot = match || jestSnapshot.toMatchSnapshot;
157+
const getState = snapshotStateGetter || snapshotState.get;
158158

159-
var state = getState();
159+
const state = getState();
160160

161-
var context = {
162-
dontThrow: function () {},
161+
const context = {
162+
dontThrow() {},
163163
currentTestName: this.title,
164164
snapshotState: state
165165
};
166166

167-
var result = toMatchSnapshot.call(context, tree);
167+
const result = toMatchSnapshot.call(context, tree);
168+
169+
let message = 'Please check your code or --update-snapshots\n\n';
168170

169-
var message = 'Please check your code or --update-snapshots\n\n';
170171
if (optionalMessage) {
171172
message += indentString(optionalMessage, 2);
172173
}
174+
173175
if (typeof result.message === 'function') {
174176
message += indentString(result.message(), 2);
175177
}

lib/cli.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ exports.run = function () {
3131
' ava [<file|directory|glob> ...]',
3232
'',
3333
'Options',
34-
' --init Add AVA to your project',
35-
' --fail-fast Stop after first test failure',
36-
' --serial, -s Run tests serially',
37-
' --tap, -t Generate TAP output',
38-
' --verbose, -v Enable verbose output',
39-
' --no-cache Disable the transpiler cache',
40-
' --no-power-assert Disable Power Assert',
41-
' --match, -m Only run tests with matching title (Can be repeated)',
42-
' --watch, -w Re-run tests when tests and source files change',
43-
' --source, -S Pattern to match source files so tests can be re-run (Can be repeated)',
44-
' --timeout, -T Set global timeout',
45-
' --concurrency, -c Maximum number of test files running at the same time (EXPERIMENTAL)',
46-
' --update-snapshots, -u Update snapshots',
34+
' --init Add AVA to your project',
35+
' --fail-fast Stop after first test failure',
36+
' --serial, -s Run tests serially',
37+
' --tap, -t Generate TAP output',
38+
' --verbose, -v Enable verbose output',
39+
' --no-cache Disable the transpiler cache',
40+
' --no-power-assert Disable Power Assert',
41+
' --match, -m Only run tests with matching title (Can be repeated)',
42+
' --watch, -w Re-run tests when tests and source files change',
43+
' --source, -S Pattern to match source files so tests can be re-run (Can be repeated)',
44+
' --timeout, -T Set global timeout',
45+
' --concurrency, -c Maximum number of test files running at the same time (EXPERIMENTAL)',
46+
' --update-snapshots, -u Update snapshots',
4747
'',
4848
'Examples',
4949
' ava',

lib/enhance-assert.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ module.exports.NON_ENHANCED_PATTERNS = [
3131
];
3232

3333
function enhanceAssert(opts) {
34-
var empower = require('empower-core');
34+
const empower = require('empower-core');
3535

36-
var enhanced = empower(
36+
const enhanced = empower(
3737
opts.assert,
3838
{
3939
destructive: false,
@@ -49,9 +49,9 @@ function enhanceAssert(opts) {
4949
}
5050

5151
function formatter() {
52-
var createFormatter = require('power-assert-context-formatter');
53-
var SuccinctRenderer = require('power-assert-renderer-succinct');
54-
var AssertionRenderer = require('power-assert-renderer-assertion');
52+
const createFormatter = require('power-assert-context-formatter');
53+
const SuccinctRenderer = require('power-assert-renderer-succinct');
54+
const AssertionRenderer = require('power-assert-renderer-assertion');
5555

5656
return createFormatter({
5757
renderers: [

lib/snapshot-state.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
'use strict';
2-
var path = require('path');
3-
var jestSnapshot = require('jest-snapshot');
4-
var globals = require('./globals');
2+
const path = require('path');
3+
const jestSnapshot = require('jest-snapshot');
4+
const globals = require('./globals');
55

6-
var x = module.exports;
6+
const x = module.exports;
77

8-
x.get = function (initializeState, globalsOptions) {
8+
x.get = (initializeState, globalsOptions) => {
99
if (!x.state) {
1010
// set defaults - this allows tests to mock deps easily
11-
var options = globalsOptions || globals.options;
12-
var initializeSnapshotState = initializeState || jestSnapshot.initializeSnapshotState;
11+
const options = globalsOptions || globals.options;
12+
const initializeSnapshotState = initializeState || jestSnapshot.initializeSnapshotState;
1313

14-
var filename = options.file;
15-
var dirname = path.dirname(filename);
16-
var snapshotFileName = path.basename(filename) + '.snap';
17-
var snapshotsFolder = path.join(dirname, '__snapshots__', snapshotFileName);
14+
const filename = options.file;
15+
const dirname = path.dirname(filename);
16+
const snapshotFileName = path.basename(filename) + '.snap';
17+
const snapshotsFolder = path.join(dirname, '__snapshots__', snapshotFileName);
1818

1919
x.state = initializeSnapshotState(
2020
filename,

readme.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,19 @@ $ ava --help
153153
ava [<file|directory|glob> ...]
154154

155155
Options
156-
--init Add AVA to your project
157-
--fail-fast Stop after first test failure
158-
--serial, -s Run tests serially
159-
--tap, -- [ ] Generate TAP output
160-
--verbose, -v Enable verbose output
161-
--no-cache Disable the transpiler cache
162-
--no-power-assert Disable Power Assert
163-
--match, -m Only run tests with matching title (Can be repeated)
164-
--watch, -w Re-run tests when tests and source files change
165-
--source, -S Pattern to match source files so tests can be re-run (Can be repeated)
166-
--timeout, -T Set global timeout
167-
--concurrency, -c Maximum number of test files running at the same time (EXPERIMENTAL)
168-
--update-snapshots, -u Update all snapshots
156+
--init Add AVA to your project
157+
--fail-fast Stop after first test failure
158+
--serial, -s Run tests serially
159+
--tap, -- [ ] Generate TAP output
160+
--verbose, -v Enable verbose output
161+
--no-cache Disable the transpiler cache
162+
--no-power-assert Disable Power Assert
163+
--match, -m Only run tests with matching title (Can be repeated)
164+
--watch, -w Re-run tests when tests and source files change
165+
--source, -S Pattern to match source files so tests can be re-run (Can be repeated)
166+
--timeout, -T Set global timeout
167+
--concurrency, -c Maximum number of test files running at the same time (EXPERIMENTAL)
168+
--update-snapshots, -u Update all snapshots
169169

170170
Examples
171171
ava

test/assert.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'use strict';
2-
var test = require('tap').test;
3-
var Promise = require('bluebird');
4-
var sinon = require('sinon');
5-
var assert = require('../lib/assert');
2+
const test = require('tap').test;
3+
const sinon = require('sinon');
4+
const assert = require('../lib/assert');
65

76
test('.pass()', t => {
87
t.doesNotThrow(() => {
@@ -492,19 +491,17 @@ test('.deepEqual() should not mask RangeError from underlying assert', t => {
492491
t.end();
493492
});
494493

495-
test('snapshot makes a snapshot using a library and global options', function (t) {
496-
var saveSpy = sinon.spy();
497-
var state = {save: saveSpy};
498-
var stateGetter = sinon.stub().returns(state);
499-
var matchStub = sinon.stub().returns({
500-
pass: true
501-
});
494+
test('snapshot makes a snapshot using a library and global options', t => {
495+
const saveSpy = sinon.spy();
496+
const state = {save: saveSpy};
497+
const stateGetter = sinon.stub().returns(state);
498+
const matchStub = sinon.stub().returns({pass: true});
502499

503500
assert.title = 'Test name';
504501

505502
t.plan(4);
506503

507-
t.doesNotThrow(function () {
504+
t.doesNotThrow(() => {
508505
assert._snapshot('tree', undefined, matchStub, stateGetter);
509506
});
510507

@@ -522,19 +519,19 @@ test('snapshot makes a snapshot using a library and global options', function (t
522519
t.end();
523520
});
524521

525-
test('if snapshot fails, prints a message', function (t) {
526-
var saveSpy = sinon.spy();
527-
var state = {save: saveSpy};
528-
var stateGetter = sinon.stub().returns(state);
529-
var messageStub = sinon.stub().returns('message');
530-
var matchStub = sinon.stub().returns({
522+
test('if snapshot fails, prints a message', t => {
523+
const saveSpy = sinon.spy();
524+
const state = {save: saveSpy};
525+
const stateGetter = sinon.stub().returns(state);
526+
const messageStub = sinon.stub().returns('message');
527+
const matchStub = sinon.stub().returns({
531528
pass: false,
532529
message: messageStub
533530
});
534531

535532
t.plan(2);
536533

537-
t.throws(function () {
534+
t.throws(() => {
538535
assert._snapshot('tree', undefined, matchStub, stateGetter);
539536
});
540537

test/snapshot-state.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
'use strict';
2+
const path = require('path');
3+
const test = require('tap').test;
4+
const sinon = require('sinon');
5+
const snapshotState = require('../lib/snapshot-state');
26

3-
var path = require('path');
4-
var test = require('tap').test;
5-
var sinon = require('sinon');
6-
var snapshotState = require('../lib/snapshot-state');
7-
8-
test('snapshot state gets created and returned', function (t) {
9-
var stateStub = sinon.stub().returns('state');
7+
test('snapshot state gets created and returned', t => {
8+
const stateStub = sinon.stub().returns('state');
109

1110
t.plan(3);
1211

13-
t.doesNotThrow(function () {
14-
var result = snapshotState.get(stateStub, {
12+
t.doesNotThrow(() => {
13+
const result = snapshotState.get(stateStub, {
1514
file: path.join('hello', 'world.test.js'),
1615
updateSnapshots: false
1716
});
@@ -29,16 +28,15 @@ test('snapshot state gets created and returned', function (t) {
2928
t.end();
3029
});
3130

32-
test('snapshot state is returned immediately if it already exists', function (t) {
33-
var stateSpy = sinon.spy();
31+
test('snapshot state is returned immediately if it already exists', t => {
32+
const stateSpy = sinon.spy();
3433

3534
t.plan(3);
3635

3736
snapshotState.state = 'already made state';
3837

39-
t.doesNotThrow(function () {
40-
var result = snapshotState.get(stateSpy);
41-
38+
t.doesNotThrow(() => {
39+
const result = snapshotState.get(stateSpy);
4240
t.is(result, 'already made state');
4341
});
4442

0 commit comments

Comments
 (0)