node-tdd 3.3.2 → 3.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/util/desc.js CHANGED
@@ -1,39 +1,18 @@
1
- "use strict";
2
-
3
- const assert = require('assert');
4
-
5
- const path = require('path');
6
-
7
- const fs = require('smart-fs');
8
-
9
- const callsites = require('callsites');
10
-
11
- const get = require('lodash.get');
12
-
13
- const {
14
- fileURLToPath
15
- } = require('url');
16
-
17
- const minimist = require('minimist');
18
-
19
- const tmp = require('tmp');
20
-
21
- const Joi = require('joi-strict');
22
-
23
- const RequestRecorder = require('../modules/request-recorder');
24
-
25
- const EnvManager = require('../modules/env-manager');
26
-
27
- const TimeKeeper = require('../modules/time-keeper');
28
-
29
- const LogRecorder = require('../modules/log-recorder');
30
-
31
- const RandomSeeder = require('../modules/random-seeder');
32
-
33
- const {
34
- getParents,
35
- genCassetteName
36
- } = require('./mocha-test');
1
+ import assert from 'assert';
2
+ import path from 'path';
3
+ import fs from 'smart-fs';
4
+ import callsites from 'callsites';
5
+ import get from 'lodash.get';
6
+ import { fileURLToPath } from 'url';
7
+ import minimist from 'minimist';
8
+ import tmp from 'tmp';
9
+ import Joi from 'joi-strict';
10
+ import RequestRecorder from '../modules/request-recorder.js';
11
+ import EnvManager from '../modules/env-manager.js';
12
+ import TimeKeeper from '../modules/time-keeper.js';
13
+ import LogRecorder from '../modules/log-recorder.js';
14
+ import RandomSeeder from '../modules/random-seeder.js';
15
+ import { getParents, genCassetteName } from './mocha-test.js';
37
16
 
38
17
  const mocha = {
39
18
  it,
@@ -49,13 +28,19 @@ const mocha = {
49
28
  const desc = (suiteName, optsOrTests, testsOrNull = null) => {
50
29
  const opts = testsOrNull === null ? {} : optsOrTests;
51
30
  const tests = testsOrNull === null ? optsOrTests : testsOrNull;
52
- const filenameOrUrl = callsites()[1].getFileName(); // eslint-disable-next-line @blackflux/rules/istanbul-prevent-ignore
53
-
54
- /* istanbul ignore next */
55
31
 
56
- const testFile = path.resolve(filenameOrUrl.startsWith('file://') ? fileURLToPath(filenameOrUrl) : filenameOrUrl);
57
-
58
- const resolve = name => path.join(path.dirname(testFile), name.replace(/\$FILENAME/g, path.basename(testFile)));
32
+ const filenameOrUrl = callsites()[1].getFileName();
33
+ const testFile = path.resolve(
34
+ filenameOrUrl.startsWith('file://')
35
+ ? fileURLToPath(filenameOrUrl)
36
+ // eslint-disable-next-line @blackflux/rules/c8-prevent-ignore
37
+ /* c8 ignore next */
38
+ : filenameOrUrl
39
+ );
40
+ const resolve = (name) => path.join(
41
+ path.dirname(testFile),
42
+ name.replace(/\$FILENAME/g, path.basename(testFile))
43
+ );
59
44
 
60
45
  Joi.assert(opts, Joi.object().keys({
61
46
  useTmpDir: Joi.boolean().optional(),
@@ -63,11 +48,15 @@ const desc = (suiteName, optsOrTests, testsOrNull = null) => {
63
48
  nockFolder: Joi.string().optional(),
64
49
  nockModifiers: Joi.object().optional().pattern(Joi.string(), Joi.function()),
65
50
  nockStripHeaders: Joi.boolean().optional(),
66
- nockReqHeaderOverwrite: Joi.object().optional().pattern(Joi.string(), Joi.alternatives(Joi.function(), Joi.string())),
51
+ nockReqHeaderOverwrite: Joi.object().optional()
52
+ .pattern(Joi.string(), Joi.alternatives(Joi.function(), Joi.string())),
67
53
  fixtureFolder: Joi.string().optional(),
68
54
  envVarsFile: Joi.string().optional(),
69
55
  envVars: Joi.object().optional().unknown(true).pattern(Joi.string(), Joi.string()),
70
- timestamp: Joi.alternatives(Joi.number().integer().min(0), Joi.date().iso()).optional(),
56
+ timestamp: Joi.alternatives(
57
+ Joi.number().integer().min(0),
58
+ Joi.date().iso()
59
+ ).optional(),
71
60
  record: Joi.any().optional(),
72
61
  cryptoSeed: Joi.string().optional(),
73
62
  cryptoSeedReseed: Joi.when('cryptoSeed', {
@@ -92,6 +81,7 @@ const desc = (suiteName, optsOrTests, testsOrNull = null) => {
92
81
  const cryptoSeedReseed = get(opts, 'cryptoSeedReseed', false);
93
82
  const timeout = get(opts, 'timeout', null);
94
83
  const nockHeal = get(minimist(process.argv.slice(2)), 'nock-heal', false);
84
+
95
85
  let dir = null;
96
86
  let requestRecorder = null;
97
87
  let envManagerFile = null;
@@ -101,31 +91,22 @@ const desc = (suiteName, optsOrTests, testsOrNull = null) => {
101
91
  let randomSeeder = null;
102
92
 
103
93
  const getArgs = () => ({
104
- capture: async fn => {
94
+ capture: async (fn) => {
105
95
  try {
106
96
  await fn();
107
97
  } catch (e) {
108
98
  return e;
109
99
  }
110
-
111
- throw new assert.AssertionError({
112
- message: 'expected [Function] to throw an error'
113
- });
100
+ throw new assert.AssertionError({ message: 'expected [Function] to throw an error' });
114
101
  },
115
- fixture: name => {
102
+ fixture: (name) => {
116
103
  const filepath = fs.guessFile(path.join(fixtureFolder, name));
117
-
118
104
  if (filepath === null) {
119
- throw new assert.AssertionError({
120
- message: `fixture "${name}" not found or ambiguous`
121
- });
105
+ throw new assert.AssertionError({ message: `fixture "${name}" not found or ambiguous` });
122
106
  }
123
-
124
107
  return fs.smartRead(filepath);
125
108
  },
126
- ...(dir === null ? {} : {
127
- dir
128
- }),
109
+ ...(dir === null ? {} : { dir }),
129
110
  ...(logRecorder === null ? {} : {
130
111
  recorder: {
131
112
  verbose: logRecorder.verbose,
@@ -134,56 +115,37 @@ const desc = (suiteName, optsOrTests, testsOrNull = null) => {
134
115
  }
135
116
  })
136
117
  });
137
-
138
118
  let beforeCb = () => {};
139
-
140
119
  let afterCb = () => {};
141
-
142
120
  let beforeEachCb = () => {};
121
+ let afterEachCb = () => {};
143
122
 
144
- let afterEachCb = () => {}; // eslint-disable-next-line func-names
145
-
146
-
123
+ // eslint-disable-next-line func-names
147
124
  mocha.describe(suiteName, function () {
148
125
  return (async () => {
149
126
  if (timeout !== null) {
150
127
  this.timeout(timeout);
151
- } // eslint-disable-next-line func-names
152
-
128
+ }
153
129
 
130
+ // eslint-disable-next-line func-names
154
131
  mocha.before(function () {
155
132
  return (async () => {
156
133
  if (getParents(this.test).length === 3 && fs.existsSync(envVarsFile)) {
157
- envManagerFile = EnvManager({
158
- envVars: fs.smartRead(envVarsFile),
159
- allowOverwrite: false
160
- });
134
+ envManagerFile = EnvManager({ envVars: fs.smartRead(envVarsFile), allowOverwrite: false });
161
135
  envManagerFile.apply();
162
136
  }
163
-
164
137
  if (envVars !== null) {
165
- envManagerDesc = EnvManager({
166
- envVars,
167
- allowOverwrite: false
168
- });
138
+ envManagerDesc = EnvManager({ envVars, allowOverwrite: false });
169
139
  envManagerDesc.apply();
170
140
  }
171
-
172
141
  if (timestamp !== null) {
173
- timeKeeper = TimeKeeper({
174
- timestamp
175
- });
142
+ timeKeeper = TimeKeeper({ timestamp });
176
143
  timeKeeper.inject();
177
144
  }
178
-
179
145
  if (cryptoSeed !== null) {
180
- randomSeeder = RandomSeeder({
181
- seed: cryptoSeed,
182
- reseed: cryptoSeedReseed
183
- });
146
+ randomSeeder = RandomSeeder({ seed: cryptoSeed, reseed: cryptoSeedReseed });
184
147
  randomSeeder.inject();
185
148
  }
186
-
187
149
  if (useNock === true) {
188
150
  requestRecorder = RequestRecorder({
189
151
  cassetteFolder: `${nockFolder}/`,
@@ -194,56 +156,47 @@ const desc = (suiteName, optsOrTests, testsOrNull = null) => {
194
156
  modifiers: nockModifiers
195
157
  });
196
158
  }
197
-
198
159
  await beforeCb.call(this);
199
160
  })();
200
- }); // eslint-disable-next-line func-names
161
+ });
201
162
 
163
+ // eslint-disable-next-line func-names
202
164
  mocha.after(function () {
203
165
  return (async () => {
204
166
  if (requestRecorder !== null) {
205
167
  requestRecorder.shutdown();
206
168
  requestRecorder = null;
207
169
  }
208
-
209
170
  if (randomSeeder !== null) {
210
171
  randomSeeder.release();
211
172
  randomSeeder = null;
212
173
  }
213
-
214
174
  if (timeKeeper !== null) {
215
175
  timeKeeper.release();
216
176
  timeKeeper = null;
217
177
  }
218
-
219
178
  if (envManagerDesc !== null) {
220
179
  envManagerDesc.unapply();
221
180
  envManagerDesc = null;
222
181
  }
223
-
224
182
  if (envManagerFile !== null) {
225
183
  envManagerFile.unapply();
226
184
  envManagerFile = null;
227
185
  }
228
-
229
186
  await afterCb.call(this);
230
187
  })();
231
- }); // eslint-disable-next-line func-names
188
+ });
232
189
 
190
+ // eslint-disable-next-line func-names
233
191
  mocha.beforeEach(function () {
234
192
  return (async () => {
235
193
  if (useTmpDir === true) {
236
194
  tmp.setGracefulCleanup();
237
- dir = tmp.dirSync({
238
- keep: false,
239
- unsafeCleanup: true
240
- }).name;
195
+ dir = tmp.dirSync({ keep: false, unsafeCleanup: true }).name;
241
196
  }
242
-
243
197
  if (useNock === true) {
244
198
  await requestRecorder.inject(genCassetteName(this.currentTest));
245
199
  }
246
-
247
200
  if (record !== false) {
248
201
  logRecorder = LogRecorder({
249
202
  verbose: process.argv.slice(2).includes('--verbose'),
@@ -251,61 +204,56 @@ const desc = (suiteName, optsOrTests, testsOrNull = null) => {
251
204
  });
252
205
  logRecorder.inject();
253
206
  }
254
-
255
207
  await beforeEachCb.call(this, getArgs());
256
208
  })();
257
- }); // eslint-disable-next-line func-names
209
+ });
258
210
 
211
+ // eslint-disable-next-line func-names
259
212
  mocha.afterEach(function () {
260
213
  return (async () => {
261
214
  await afterEachCb.call(this, getArgs());
262
-
263
215
  if (logRecorder !== null) {
264
216
  logRecorder.release();
265
217
  logRecorder = null;
266
218
  }
267
-
268
219
  if (requestRecorder !== null) {
269
220
  await requestRecorder.release();
270
221
  }
271
-
272
222
  if (dir !== null) {
273
223
  dir = null;
274
224
  }
275
225
  })();
276
226
  });
277
- const globalsPrev = Object.keys(mocha).reduce((p, key) => Object.assign(p, {
278
- [key]: global[key]
279
- }));
280
-
281
- global.it = (testName, fn) => mocha.it(testName, fn.length === 0 || /^[^(=]*\({/.test(fn.toString()) // eslint-disable-next-line func-names
282
- ? function () {
283
- return fn.call(this, getArgs());
284
- } // eslint-disable-next-line func-names
285
- : function (done) {
286
- return fn.call(this, done);
287
- });
288
227
 
228
+ const globalsPrev = Object.keys(mocha)
229
+ .reduce((p, key) => Object.assign(p, { [key]: global[key] }));
230
+ global.it = (testName, fn) => mocha.it(
231
+ testName,
232
+ fn.length === 0 || /^[^(=]*\({/.test(fn.toString())
233
+ // eslint-disable-next-line func-names
234
+ ? function () {
235
+ return fn.call(this, getArgs());
236
+ }
237
+ // eslint-disable-next-line func-names
238
+ : function (done) {
239
+ return fn.call(this, done);
240
+ }
241
+ );
289
242
  global.specify = global.it;
290
243
  global.describe = desc;
291
244
  global.context = global.describe;
292
-
293
- global.before = fn => {
245
+ global.before = (fn) => {
294
246
  beforeCb = fn;
295
247
  };
296
-
297
- global.after = fn => {
248
+ global.after = (fn) => {
298
249
  afterCb = fn;
299
250
  };
300
-
301
- global.beforeEach = fn => {
251
+ global.beforeEach = (fn) => {
302
252
  beforeEachCb = fn;
303
253
  };
304
-
305
- global.afterEach = fn => {
254
+ global.afterEach = (fn) => {
306
255
  afterEachCb = fn;
307
256
  };
308
-
309
257
  await tests.call(this);
310
258
  Object.entries(globalsPrev).forEach(([k, v]) => {
311
259
  global[k] = v;
@@ -313,5 +261,4 @@ const desc = (suiteName, optsOrTests, testsOrNull = null) => {
313
261
  })();
314
262
  });
315
263
  };
316
-
317
- module.exports = desc;
264
+ export default desc;
@@ -1,19 +1,19 @@
1
- "use strict";
2
-
3
- const getParents = test => {
1
+ export const getParents = (test) => {
4
2
  const names = [];
5
3
  let cTest = test;
6
-
7
4
  while (cTest !== undefined) {
8
5
  names.splice(0, 0, cTest.title);
9
6
  cTest = cTest.parent;
10
7
  }
11
-
12
8
  return names;
13
9
  };
14
10
 
15
- module.exports.getParents = getParents;
16
-
17
- const genCassetteName = test => getParents(test).filter(e => !!e).map(e => e.replace(/[^a-zA-Z0-9]+/g, '-').replace(/^-+|-+$/g, '').replace(/^./, c => c.toLowerCase()).replace(/-(.)/g, (_, char) => char.toUpperCase())).concat(['recording.json']).join('_');
18
-
19
- module.exports.genCassetteName = genCassetteName;
11
+ export const genCassetteName = (test) => getParents(test)
12
+ .filter((e) => !!e)
13
+ .map((e) => e
14
+ .replace(/[^a-zA-Z0-9]+/g, '-')
15
+ .replace(/^-+|-+$/g, '')
16
+ .replace(/^./, (c) => c.toLowerCase())
17
+ .replace(/-(.)/g, (_, char) => char.toUpperCase()))
18
+ .concat(['recording.json'])
19
+ .join('_');
package/package.json CHANGED
@@ -1,21 +1,22 @@
1
1
  {
2
2
  "name": "node-tdd",
3
- "version": "3.3.2",
3
+ "type": "module",
4
+ "version": "3.4.1",
4
5
  "description": "Drop in extension for mocha to abstract commonly used test setups",
5
6
  "main": "lib/index.js",
6
7
  "scripts": {
7
8
  "test": "yarn run clean && yarn run gardener && yarn run test-simple",
8
9
  "clean": "rm -rf lib",
9
- "build": "npx babel src --out-dir lib --copy-files --include-dotfiles --config-file ./.babelrc",
10
+ "build": "cp -rf ./src ./lib",
10
11
  "build-clean": "yarn run clean && yarn run build",
11
- "test-simple": "nyc mocha \"./test/**/*.spec.js\"",
12
+ "test-simple": "c8 mocha --experimental-loader=./test/hot.js \"./test/**/*.spec.js\"",
12
13
  "docker": "docker run --net host -u`id -u`:`id -g` -v $(pwd):/user/project -v ~/.aws:/user/.aws -v ~/.npmrc:/user/.npmrc -w /user/project -it --entrypoint /bin/bash",
13
14
  "t": "yarn test",
14
15
  "ts": "yarn run test-simple",
15
16
  "tsv": "yarn run test-simple --verbose",
16
17
  "coveralls": "node ./node_modules/coveralls/bin/coveralls.js < ./coverage/lcov.info",
17
18
  "semantic-release": "yarn run build-clean && npx semantic-release",
18
- "gardener": "node gardener",
19
+ "gardener": "node gardener.js",
19
20
  "u": "yarn upgrade --latest --force",
20
21
  "i": "yarn install --frozen-lockfile",
21
22
  "it": "yarn run i && yarn run t"
@@ -41,29 +42,26 @@
41
42
  },
42
43
  "homepage": "https://github.com/blackflux/node-tdd#readme",
43
44
  "devDependencies": {
44
- "@babel/cli": "7.14.8",
45
- "@babel/core": "7.15.0",
46
- "@babel/register": "7.15.3",
47
- "@blackflux/eslint-plugin-rules": "2.0.3",
48
- "@blackflux/robo-config-plugin": "5.3.0",
49
- "aws-sdk": "2.981.0",
50
- "aws-sdk-wrap": "9.6.0",
51
- "axios": "0.24.0",
52
- "babel-eslint": "10.1.0",
53
- "babel-preset-latest-node": "5.5.1",
54
- "chai": "4.3.4",
45
+ "@babel/core": "7.17.10",
46
+ "@babel/eslint-parser": "7.17.0",
47
+ "@babel/register": "7.17.7",
48
+ "@blackflux/eslint-plugin-rules": "2.1.0",
49
+ "@blackflux/robo-config-plugin": "7.7.12",
50
+ "aws-sdk": "2.1131.0",
51
+ "aws-sdk-wrap": "12.1.3",
52
+ "axios": "0.27.2",
53
+ "c8": "7.11.2",
54
+ "chai": "4.3.6",
55
55
  "coveralls": "3.1.1",
56
- "eslint": "7.32.0",
57
- "eslint-config-airbnb-base": "14.2.1",
58
- "eslint-plugin-import": "2.24.2",
56
+ "eslint": "8.15.0",
57
+ "eslint-config-airbnb-base": "15.0.0",
58
+ "eslint-plugin-import": "2.26.0",
59
59
  "eslint-plugin-json": "3.1.0",
60
- "eslint-plugin-markdown": "2.2.0",
61
- "eslint-plugin-mocha": "9.0.0",
62
- "fancy-log": "1.3.3",
63
- "js-gardener": "3.0.3",
64
- "lambda-monitor-logger": "3.0.0",
65
- "nyc": "15.1.0",
66
- "semantic-release": "17.4.7"
60
+ "eslint-plugin-markdown": "2.2.1",
61
+ "eslint-plugin-mocha": "10.0.3",
62
+ "fancy-log": "2.0.0",
63
+ "js-gardener": "3.0.5",
64
+ "lambda-monitor-logger": "3.2.2"
67
65
  },
68
66
  "licenses": [
69
67
  {
@@ -72,54 +70,23 @@
72
70
  }
73
71
  ],
74
72
  "engines": {
75
- "node": ">= 12"
76
- },
77
- "nyc": {
78
- "exclude": [
79
- "gardener.js",
80
- "node_modules/*",
81
- "coverage/*",
82
- "lib/*"
83
- ],
84
- "tempDir": "./coverage/.nyc_output",
85
- "report-dir": "./coverage",
86
- "check-coverage": true,
87
- "per-file": false,
88
- "lines": 100,
89
- "statements": 100,
90
- "functions": 100,
91
- "branches": 100,
92
- "include": [
93
- "**/*.js"
94
- ],
95
- "reporter": [
96
- "lcov",
97
- "text-summary"
98
- ],
99
- "require": [
100
- "@babel/register"
101
- ],
102
- "extension": [],
103
- "cache": true,
104
- "all": true,
105
- "babel": true
73
+ "node": ">= 14"
106
74
  },
107
75
  "files": [
108
76
  "lib"
109
77
  ],
110
78
  "dependencies": {
111
- "callsites": "3.1.0",
79
+ "callsites": "4.0.0",
112
80
  "compare-urls": "2.0.0",
113
- "joi-strict": "2.0.0",
81
+ "joi-strict": "2.0.1",
114
82
  "lodash.clonedeep": "4.5.0",
115
83
  "lodash.get": "4.4.2",
116
- "minimist": "1.2.5",
117
- "nock": "13.1.3",
118
- "object-scan": "17.0.0",
119
- "smart-fs": "2.0.2",
84
+ "minimist": "1.2.6",
85
+ "nock": "13.2.4",
86
+ "object-scan": "18.0.1",
87
+ "smart-fs": "3.0.1",
120
88
  "timekeeper": "2.2.0",
121
89
  "tmp": "0.2.1",
122
- "uuid": "8.3.0",
123
90
  "xml2js": "0.4.23"
124
91
  }
125
92
  }