|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -require('../common'); |
4 | | -const assert = require('assert'); |
5 | | -const { mock } = require('node:test'); |
| 3 | +const { |
| 4 | + ObjectAssign, |
| 5 | + ObjectDefineProperty, |
| 6 | +} = primordials; |
6 | 7 |
|
7 | | -console.log('Testing mock.property() with process.env...'); |
| 8 | +const { test, suite, before, after, beforeEach, afterEach } = require('internal/test_runner/harness'); |
| 9 | +const { run } = require('internal/test_runner/runner'); |
8 | 10 |
|
9 | | -const hadOriginal = Object.prototype.hasOwnProperty.call(process.env, 'TEST_ENV'); |
10 | | -const original = process.env.TEST_ENV; |
| 11 | +module.exports = test; |
| 12 | +ObjectAssign(module.exports, { |
| 13 | + after, |
| 14 | + afterEach, |
| 15 | + before, |
| 16 | + beforeEach, |
| 17 | + describe: suite, |
| 18 | + it: test, |
| 19 | + run, |
| 20 | + suite, |
| 21 | + test, |
| 22 | +}); |
11 | 23 |
|
| 24 | +let lazyMock; |
12 | 25 |
|
13 | | -const tracker = mock.property(process.env, 'TEST_ENV', 'mocked'); |
| 26 | +ObjectDefineProperty(module.exports, 'mock', { |
| 27 | + __proto__: null, |
| 28 | + configurable: true, |
| 29 | + enumerable: true, |
| 30 | + get() { |
| 31 | + if (lazyMock === undefined) { |
| 32 | + const { MockTracker } = require('internal/test_runner/mock/mock'); |
14 | 33 |
|
15 | | -assert.strictEqual(process.env.TEST_ENV, 'mocked'); |
16 | | -console.log('Mocked process.env.TEST_ENV successfully'); |
| 34 | + lazyMock = new MockTracker(); |
| 35 | + } |
17 | 36 |
|
18 | | -tracker.restore(); |
| 37 | + return lazyMock; |
| 38 | + }, |
| 39 | +}); |
19 | 40 |
|
20 | | -if (hadOriginal) { |
21 | | - assert.strictEqual(process.env.TEST_ENV, original); |
22 | | -} else { |
23 | | - assert.ok(!('TEST_ENV' in process.env)); |
24 | | -} |
| 41 | +let lazySnapshot; |
25 | 42 |
|
26 | | -console.log('Restored original process.env.TEST_ENV'); |
| 43 | +ObjectDefineProperty(module.exports, 'snapshot', { |
| 44 | + __proto__: null, |
| 45 | + configurable: true, |
| 46 | + enumerable: true, |
| 47 | + get() { |
| 48 | + if (lazySnapshot === undefined) { |
| 49 | + const { |
| 50 | + setDefaultSnapshotSerializers, |
| 51 | + setResolveSnapshotPath, |
| 52 | + } = require('internal/test_runner/snapshot'); |
| 53 | + |
| 54 | + lazySnapshot = { |
| 55 | + __proto__: null, |
| 56 | + setDefaultSnapshotSerializers, |
| 57 | + setResolveSnapshotPath, |
| 58 | + }; |
| 59 | + } |
| 60 | + |
| 61 | + return lazySnapshot; |
| 62 | + }, |
| 63 | +}); |
| 64 | + |
| 65 | +ObjectDefineProperty(module.exports, 'assert', { |
| 66 | + __proto__: null, |
| 67 | + configurable: true, |
| 68 | + enumerable: true, |
| 69 | + get() { |
| 70 | + const { register } = require('internal/test_runner/assert'); |
| 71 | + const assert = { __proto__: null, register }; |
| 72 | + ObjectDefineProperty(module.exports, 'assert', assert); |
| 73 | + return assert; |
| 74 | + }, |
| 75 | +}); |
0 commit comments