|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +// This tests that the snapshot works with built-in coverage collection. |
| 4 | + |
| 5 | +const common = require('../common'); |
| 6 | +common.skipIfInspectorDisabled(); |
| 7 | + |
| 8 | +const { spawnSyncAndExitWithoutError } = require('../common/child_process'); |
| 9 | +const tmpdir = require('../common/tmpdir'); |
| 10 | +const fixtures = require('../common/fixtures'); |
| 11 | +const fs = require('fs'); |
| 12 | +const assert = require('assert'); |
| 13 | + |
| 14 | +tmpdir.refresh(); |
| 15 | +const blobPath = tmpdir.resolve('snapshot.blob'); |
| 16 | +const file = fixtures.path('empty.js'); |
| 17 | + |
| 18 | +function filterCoverageFiles(name) { |
| 19 | + return name.startsWith('coverage') && name.endsWith('.json'); |
| 20 | +} |
| 21 | +{ |
| 22 | + // Create the snapshot. |
| 23 | + const { child } = spawnSyncAndExitWithoutError(process.execPath, [ |
| 24 | + '--snapshot-blob', |
| 25 | + blobPath, |
| 26 | + '--build-snapshot', |
| 27 | + file, |
| 28 | + ], { |
| 29 | + cwd: tmpdir.path, |
| 30 | + env: { |
| 31 | + ...process.env, |
| 32 | + NODE_V8_COVERAGE: tmpdir.path, |
| 33 | + NODE_DEBUG_NATIVE: 'inspector_profiler', |
| 34 | + } |
| 35 | + }); |
| 36 | + const files = fs.readdirSync(tmpdir.path); |
| 37 | + console.log('Files in tmpdir.path', files); // Log for debugging the test. |
| 38 | + const coverage = files.filter(filterCoverageFiles); |
| 39 | + console.log(child.stderr.toString()); |
| 40 | + assert.strictEqual(coverage.length, 1); |
| 41 | +} |
| 42 | + |
| 43 | +{ |
| 44 | + const { child } = spawnSyncAndExitWithoutError(process.execPath, [ |
| 45 | + '--snapshot-blob', |
| 46 | + blobPath, |
| 47 | + file, |
| 48 | + ], { |
| 49 | + cwd: tmpdir.path, |
| 50 | + env: { |
| 51 | + ...process.env, |
| 52 | + NODE_V8_COVERAGE: tmpdir.path, |
| 53 | + NODE_DEBUG_NATIVE: 'inspector_profiler', |
| 54 | + }, |
| 55 | + }); |
| 56 | + const files = fs.readdirSync(tmpdir.path); |
| 57 | + console.log('Files in tmpdir.path', files); // Log for debugging the test. |
| 58 | + const coverage = files.filter(filterCoverageFiles); |
| 59 | + console.log(child.stderr.toString()); |
| 60 | + assert.strictEqual(coverage.length, 2); |
| 61 | +} |
0 commit comments