node-tdd 3.4.3 → 3.5.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/LICENSE +1 -1
- package/README.md +7 -0
- package/lib/modules/cache-clearer.js +57 -0
- package/lib/util/desc.js +13 -0
- package/package.json +21 -22
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -176,6 +176,13 @@ loaded from `envVarsFile` (if allowed).
|
|
|
176
176
|
|
|
177
177
|
To allow overwriting of environment variables, prefix the name of the environment variable with `^`.
|
|
178
178
|
|
|
179
|
+
#### clearCache
|
|
180
|
+
|
|
181
|
+
Type: `boolean`<br>
|
|
182
|
+
Default: `true`
|
|
183
|
+
|
|
184
|
+
Known accessed caches will be cleared after test has executed when set to `true`.
|
|
185
|
+
|
|
179
186
|
#### timestamp
|
|
180
187
|
|
|
181
188
|
Type: `number|string`<br>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import assert from 'assert';
|
|
2
|
+
import LRU from 'lru-cache-ext';
|
|
3
|
+
|
|
4
|
+
const getFns = (obj) => {
|
|
5
|
+
const result = [];
|
|
6
|
+
const properties = [];
|
|
7
|
+
let o = obj;
|
|
8
|
+
while (o instanceof Object) {
|
|
9
|
+
properties.push(...Object.getOwnPropertyNames(o));
|
|
10
|
+
o = Object.getPrototypeOf(o);
|
|
11
|
+
}
|
|
12
|
+
for (let i = 0; i < properties.length; i += 1) {
|
|
13
|
+
const key = properties[i];
|
|
14
|
+
const value = LRU.prototype[key];
|
|
15
|
+
if (typeof value !== 'function') {
|
|
16
|
+
// eslint-disable-next-line no-continue
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
result.push({ obj, key, value });
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default () => {
|
|
25
|
+
let injected = false;
|
|
26
|
+
const fns = [
|
|
27
|
+
...getFns(LRU.prototype)
|
|
28
|
+
];
|
|
29
|
+
const caches = [];
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
inject: () => {
|
|
33
|
+
assert(injected === false);
|
|
34
|
+
fns.forEach(({ obj, key, value }) => {
|
|
35
|
+
try {
|
|
36
|
+
// eslint-disable-next-line no-param-reassign,func-names
|
|
37
|
+
obj[key] = function (...args) {
|
|
38
|
+
caches.push(this);
|
|
39
|
+
return value.call(this, ...args);
|
|
40
|
+
};
|
|
41
|
+
} catch (e) { /* ignored */ }
|
|
42
|
+
});
|
|
43
|
+
injected = true;
|
|
44
|
+
},
|
|
45
|
+
release: () => {
|
|
46
|
+
assert(injected === true);
|
|
47
|
+
fns.forEach(({ obj, key, value }) => {
|
|
48
|
+
try {
|
|
49
|
+
// eslint-disable-next-line no-param-reassign
|
|
50
|
+
obj[key] = value;
|
|
51
|
+
} catch (e) { /* ignored */ }
|
|
52
|
+
});
|
|
53
|
+
caches.splice(0).forEach((c) => c.clear());
|
|
54
|
+
injected = false;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
};
|
package/lib/util/desc.js
CHANGED
|
@@ -12,6 +12,7 @@ import EnvManager from '../modules/env-manager.js';
|
|
|
12
12
|
import TimeKeeper from '../modules/time-keeper.js';
|
|
13
13
|
import LogRecorder from '../modules/log-recorder.js';
|
|
14
14
|
import RandomSeeder from '../modules/random-seeder.js';
|
|
15
|
+
import CacheClearer from '../modules/cache-clearer.js';
|
|
15
16
|
import { getParents, genCassetteName } from './mocha-test.js';
|
|
16
17
|
|
|
17
18
|
const mocha = {
|
|
@@ -53,6 +54,7 @@ const desc = (suiteName, optsOrTests, testsOrNull = null) => {
|
|
|
53
54
|
fixtureFolder: Joi.string().optional(),
|
|
54
55
|
envVarsFile: Joi.string().optional(),
|
|
55
56
|
envVars: Joi.object().optional().unknown(true).pattern(Joi.string(), Joi.string()),
|
|
57
|
+
clearCache: Joi.boolean().optional(),
|
|
56
58
|
timestamp: Joi.alternatives(
|
|
57
59
|
Joi.number().integer().min(0),
|
|
58
60
|
Joi.date().iso()
|
|
@@ -75,6 +77,7 @@ const desc = (suiteName, optsOrTests, testsOrNull = null) => {
|
|
|
75
77
|
const fixtureFolder = resolve(get(opts, 'fixtureFolder', '$FILENAME__fixtures'));
|
|
76
78
|
const envVarsFile = resolve(get(opts, 'envVarsFile', '$FILENAME.env.yml'));
|
|
77
79
|
const envVars = get(opts, 'envVars', null);
|
|
80
|
+
const clearCache = get(opts, 'clearCache', true);
|
|
78
81
|
const timestamp = get(opts, 'timestamp', null);
|
|
79
82
|
const record = get(opts, 'record', false);
|
|
80
83
|
const cryptoSeed = get(opts, 'cryptoSeed', null);
|
|
@@ -84,6 +87,7 @@ const desc = (suiteName, optsOrTests, testsOrNull = null) => {
|
|
|
84
87
|
|
|
85
88
|
let dir = null;
|
|
86
89
|
let requestRecorder = null;
|
|
90
|
+
let cacheClearer = null;
|
|
87
91
|
let envManagerFile = null;
|
|
88
92
|
let envManagerDesc = null;
|
|
89
93
|
let timeKeeper = null;
|
|
@@ -130,6 +134,9 @@ const desc = (suiteName, optsOrTests, testsOrNull = null) => {
|
|
|
130
134
|
// eslint-disable-next-line func-names
|
|
131
135
|
mocha.before(function () {
|
|
132
136
|
return (async () => {
|
|
137
|
+
if (clearCache !== false) {
|
|
138
|
+
cacheClearer = CacheClearer();
|
|
139
|
+
}
|
|
133
140
|
if (getParents(this.test).length === 3 && fs.existsSync(envVarsFile)) {
|
|
134
141
|
envManagerFile = EnvManager({ envVars: fs.smartRead(envVarsFile), allowOverwrite: false });
|
|
135
142
|
envManagerFile.apply();
|
|
@@ -190,6 +197,9 @@ const desc = (suiteName, optsOrTests, testsOrNull = null) => {
|
|
|
190
197
|
// eslint-disable-next-line func-names
|
|
191
198
|
mocha.beforeEach(function () {
|
|
192
199
|
return (async () => {
|
|
200
|
+
if (cacheClearer !== null) {
|
|
201
|
+
cacheClearer.inject();
|
|
202
|
+
}
|
|
193
203
|
if (useTmpDir === true) {
|
|
194
204
|
tmp.setGracefulCleanup();
|
|
195
205
|
dir = tmp.dirSync({ keep: false, unsafeCleanup: true }).name;
|
|
@@ -222,6 +232,9 @@ const desc = (suiteName, optsOrTests, testsOrNull = null) => {
|
|
|
222
232
|
if (dir !== null) {
|
|
223
233
|
dir = null;
|
|
224
234
|
}
|
|
235
|
+
if (cacheClearer !== null) {
|
|
236
|
+
cacheClearer.release();
|
|
237
|
+
}
|
|
225
238
|
})();
|
|
226
239
|
});
|
|
227
240
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-tdd",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.5.1",
|
|
5
5
|
"description": "Drop in extension for mocha to abstract commonly used test setups",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"scripts": {
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
"t": "yarn test",
|
|
15
15
|
"ts": "yarn run test-simple",
|
|
16
16
|
"tsv": "yarn run test-simple --verbose",
|
|
17
|
-
"coveralls": "node ./node_modules/coveralls/bin/coveralls.js < ./coverage/lcov.info",
|
|
18
17
|
"semantic-release": "yarn run build-clean && npx semantic-release",
|
|
19
18
|
"gardener": "node gardener.js",
|
|
20
19
|
"u": "yarn upgrade --latest --force",
|
|
@@ -42,26 +41,25 @@
|
|
|
42
41
|
},
|
|
43
42
|
"homepage": "https://github.com/blackflux/node-tdd#readme",
|
|
44
43
|
"devDependencies": {
|
|
45
|
-
"@
|
|
46
|
-
"@babel/
|
|
47
|
-
"@babel/
|
|
44
|
+
"@aws-sdk/client-sqs": "3.370.0",
|
|
45
|
+
"@babel/core": "7.22.9",
|
|
46
|
+
"@babel/eslint-parser": "7.22.9",
|
|
47
|
+
"@babel/register": "7.22.5",
|
|
48
48
|
"@blackflux/eslint-plugin-rules": "2.1.0",
|
|
49
|
-
"@blackflux/robo-config-plugin": "
|
|
50
|
-
"aws-sdk": "
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"coveralls": "3.1.1",
|
|
56
|
-
"eslint": "8.15.0",
|
|
49
|
+
"@blackflux/robo-config-plugin": "9.0.1",
|
|
50
|
+
"aws-sdk-wrap": "13.0.2",
|
|
51
|
+
"axios": "1.4.0",
|
|
52
|
+
"c8": "8.0.0",
|
|
53
|
+
"chai": "4.3.7",
|
|
54
|
+
"eslint": "8.45.0",
|
|
57
55
|
"eslint-config-airbnb-base": "15.0.0",
|
|
58
|
-
"eslint-plugin-import": "2.
|
|
56
|
+
"eslint-plugin-import": "2.27.5",
|
|
59
57
|
"eslint-plugin-json": "3.1.0",
|
|
60
|
-
"eslint-plugin-markdown": "
|
|
61
|
-
"eslint-plugin-mocha": "10.0
|
|
58
|
+
"eslint-plugin-markdown": "3.0.0",
|
|
59
|
+
"eslint-plugin-mocha": "10.1.0",
|
|
62
60
|
"fancy-log": "2.0.0",
|
|
63
|
-
"js-gardener": "
|
|
64
|
-
"lambda-monitor-logger": "
|
|
61
|
+
"js-gardener": "5.0.0",
|
|
62
|
+
"lambda-monitor-logger": "4.0.0"
|
|
65
63
|
},
|
|
66
64
|
"licenses": [
|
|
67
65
|
{
|
|
@@ -81,12 +79,13 @@
|
|
|
81
79
|
"joi-strict": "2.0.1",
|
|
82
80
|
"lodash.clonedeep": "4.5.0",
|
|
83
81
|
"lodash.get": "4.4.2",
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
82
|
+
"lru-cache-ext": "3.0.2",
|
|
83
|
+
"minimist": "1.2.8",
|
|
84
|
+
"nock": "13.3.2",
|
|
85
|
+
"object-scan": "18.5.1",
|
|
87
86
|
"smart-fs": "3.0.1",
|
|
88
87
|
"timekeeper": "2.2.0",
|
|
89
88
|
"tmp": "0.2.1",
|
|
90
|
-
"xml2js": "0.
|
|
89
|
+
"xml2js": "0.6.0"
|
|
91
90
|
}
|
|
92
91
|
}
|