node-tdd 6.2.4 → 6.3.0
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/README.md +12 -0
- package/lib/modules/request-recorder.js +14 -1
- package/lib/util/desc.js +11 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -166,6 +166,18 @@ Used to customize the name of the file that environment variables are loaded fro
|
|
|
166
166
|
|
|
167
167
|
To allow overwriting of environment variables, prefix the name of the environment variable with `^`.
|
|
168
168
|
|
|
169
|
+
#### envVarsFileRecording
|
|
170
|
+
|
|
171
|
+
Type: `string`<br>
|
|
172
|
+
Default: `$FILENAME.env.recording.yml` (depends on `envVarsFile`)
|
|
173
|
+
|
|
174
|
+
Used to customize the name of the file that environment variables are loaded from,
|
|
175
|
+
if it exists and `useNock` is true and no cassette file exists.
|
|
176
|
+
|
|
177
|
+
Environment variables are loaded after `envVars` and `envVarsFile` variables are loaded.
|
|
178
|
+
|
|
179
|
+
Defined environment variables will overwrite set ones.
|
|
180
|
+
|
|
169
181
|
#### envVars
|
|
170
182
|
|
|
171
183
|
Type: `object`<br>
|
|
@@ -9,6 +9,7 @@ import get from 'lodash.get';
|
|
|
9
9
|
import cloneDeep from 'lodash.clonedeep';
|
|
10
10
|
import nockCommon from 'nock/lib/common.js';
|
|
11
11
|
import compareUrls from '../util/compare-urls.js';
|
|
12
|
+
import EnvManager from './env-manager.js';
|
|
12
13
|
import nockListener from './request-recorder/nock-listener.js';
|
|
13
14
|
import nockMock from './request-recorder/nock-mock.js';
|
|
14
15
|
import healSqs from './request-recorder/heal-sqs.js';
|
|
@@ -35,6 +36,7 @@ export default (opts) => {
|
|
|
35
36
|
Joi.string().case('lower'),
|
|
36
37
|
Joi.alternatives(Joi.string(), Joi.function())
|
|
37
38
|
),
|
|
39
|
+
envVarsFileRecording: Joi.string().optional(),
|
|
38
40
|
strict: Joi.boolean(),
|
|
39
41
|
heal: Joi.alternatives(Joi.boolean(), Joi.string()),
|
|
40
42
|
modifiers: Joi.object().pattern(
|
|
@@ -42,8 +44,9 @@ export default (opts) => {
|
|
|
42
44
|
Joi.alternatives(Joi.function(), Joi.link('#modifiers'))
|
|
43
45
|
)
|
|
44
46
|
}), 'Invalid Options Provided');
|
|
45
|
-
let nockDone = null;
|
|
46
47
|
let cassetteFilePath = null;
|
|
48
|
+
let envManagerFile = null;
|
|
49
|
+
let nockDone = null;
|
|
47
50
|
const knownCassetteNames = [];
|
|
48
51
|
const records = [];
|
|
49
52
|
const outOfOrderErrors = [];
|
|
@@ -90,6 +93,11 @@ export default (opts) => {
|
|
|
90
93
|
})));
|
|
91
94
|
}
|
|
92
95
|
|
|
96
|
+
if (!hasCassette && typeof opts.envVarsFileRecording === 'string' && fs.existsSync(opts.envVarsFileRecording)) {
|
|
97
|
+
envManagerFile = EnvManager({ envVars: fs.smartRead(opts.envVarsFileRecording), allowOverwrite: true });
|
|
98
|
+
envManagerFile.apply();
|
|
99
|
+
}
|
|
100
|
+
|
|
93
101
|
nockBack.setMode(hasCassette ? 'lockdown' : 'record');
|
|
94
102
|
nockBack.fixtures = opts.cassetteFolder;
|
|
95
103
|
nockMock.patch();
|
|
@@ -296,6 +304,11 @@ export default (opts) => {
|
|
|
296
304
|
nockListener.unsubscribeAll('no match');
|
|
297
305
|
nockMock.unpatch();
|
|
298
306
|
|
|
307
|
+
if (envManagerFile !== null) {
|
|
308
|
+
envManagerFile.unapply();
|
|
309
|
+
envManagerFile = null;
|
|
310
|
+
}
|
|
311
|
+
|
|
299
312
|
if (opts.heal !== false) {
|
|
300
313
|
fs.smartWrite(
|
|
301
314
|
cassetteFilePath,
|
package/lib/util/desc.js
CHANGED
|
@@ -38,9 +38,10 @@ const desc = (suiteName, optsOrTests, testsOrNull = null) => {
|
|
|
38
38
|
/* c8 ignore next */
|
|
39
39
|
: filenameOrUrl
|
|
40
40
|
);
|
|
41
|
-
const resolve = (name) =>
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
const resolve = (name) => (
|
|
42
|
+
name.startsWith('/')
|
|
43
|
+
? name
|
|
44
|
+
: path.join(path.dirname(testFile), name.replace(/\$FILENAME/g, path.basename(testFile)))
|
|
44
45
|
);
|
|
45
46
|
|
|
46
47
|
Joi.assert(opts, Joi.object().keys({
|
|
@@ -53,6 +54,7 @@ const desc = (suiteName, optsOrTests, testsOrNull = null) => {
|
|
|
53
54
|
.pattern(Joi.string(), Joi.alternatives(Joi.function(), Joi.string())),
|
|
54
55
|
fixtureFolder: Joi.string().optional(),
|
|
55
56
|
envVarsFile: Joi.string().optional(),
|
|
57
|
+
envVarsFileRecording: Joi.string().optional(),
|
|
56
58
|
envVars: Joi.object().optional().unknown(true).pattern(Joi.string(), Joi.string()),
|
|
57
59
|
clearCache: Joi.boolean().optional(),
|
|
58
60
|
timestamp: Joi.alternatives(
|
|
@@ -76,6 +78,11 @@ const desc = (suiteName, optsOrTests, testsOrNull = null) => {
|
|
|
76
78
|
const nockReqHeaderOverwrite = get(opts, 'nockReqHeaderOverwrite', {});
|
|
77
79
|
const fixtureFolder = resolve(get(opts, 'fixtureFolder', '$FILENAME__fixtures'));
|
|
78
80
|
const envVarsFile = resolve(get(opts, 'envVarsFile', '$FILENAME.env.yml'));
|
|
81
|
+
const envVarsFileRecording = resolve(get(
|
|
82
|
+
opts,
|
|
83
|
+
'envVarsFileRecording',
|
|
84
|
+
envVarsFile.replace(/(\.[^.]+)$/, '.recording$1')
|
|
85
|
+
));
|
|
79
86
|
const envVars = get(opts, 'envVars', null);
|
|
80
87
|
const clearCache = get(opts, 'clearCache', true);
|
|
81
88
|
const timestamp = get(opts, 'timestamp', null);
|
|
@@ -158,6 +165,7 @@ const desc = (suiteName, optsOrTests, testsOrNull = null) => {
|
|
|
158
165
|
cassetteFolder: `${nockFolder}/`,
|
|
159
166
|
stripHeaders: nockStripHeaders,
|
|
160
167
|
reqHeaderOverwrite: nockReqHeaderOverwrite,
|
|
168
|
+
envVarsFileRecording,
|
|
161
169
|
strict: true,
|
|
162
170
|
heal: nockHeal,
|
|
163
171
|
modifiers: nockModifiers
|