@@ -3,41 +3,50 @@ import path from "node:path";
3
3
import { afterEach , beforeEach , describe , it } from "node:test" ;
4
4
5
5
import { readUtf8File , remove } from "@ignored/hardhat-vnext-utils/fs" ;
6
+ import { spawnDetachedSubProcess } from "@ignored/hardhat-vnext-utils/subprocess" ;
6
7
7
- import { main } from "../../../../../src/internal/cli/telemetry/sentry/send-to-sentry.js" ;
8
8
import {
9
9
checkIfSubprocessWasExecuted ,
10
10
ROOT_PATH_TO_FIXTURE ,
11
11
} from "../helpers.js" ;
12
12
13
13
const PATH_TO_FIXTURE = path . join ( ROOT_PATH_TO_FIXTURE , "sentry" ) ;
14
14
const RESULT_FILE_PATH = path . join ( PATH_TO_FIXTURE , "sub-process-result.txt" ) ;
15
+ const SUBPROCESS_FILE_PATH = path . join (
16
+ process . cwd ( ) ,
17
+ "src" ,
18
+ "internal" ,
19
+ "cli" ,
20
+ "telemetry" ,
21
+ "sentry" ,
22
+ "subprocess.ts" ,
23
+ ) ;
15
24
16
25
describe ( "sentry-subprocess" , function ( ) {
17
26
beforeEach ( async ( ) => {
18
- process . env . HARDHAT_TEST_SUBPROCESS_RESULT_PATH = RESULT_FILE_PATH ;
19
27
await remove ( RESULT_FILE_PATH ) ;
20
28
} ) ;
21
29
22
30
afterEach ( async ( ) => {
23
- delete process . env . HARDHAT_TEST_SUBPROCESS_RESULT_PATH ;
24
31
await remove ( RESULT_FILE_PATH ) ;
25
32
} ) ;
26
33
27
34
it ( "should send an event to Sentry" , async ( ) => {
28
- process . argv [ 2 ] = "{}" ; // Send an empty object, the real payload will be tested in the tests for the "Reporter"
35
+ await spawnDetachedSubProcess ( SUBPROCESS_FILE_PATH , [ "{}" ] , {
36
+ HARDHAT_TEST_SUBPROCESS_RESULT_PATH : RESULT_FILE_PATH ,
37
+ } ) ;
29
38
30
- await main ( ) ;
31
39
await checkIfSubprocessWasExecuted ( RESULT_FILE_PATH ) ;
32
40
const fileRes = await readUtf8File ( RESULT_FILE_PATH ) ;
33
41
34
42
assert . equal ( fileRes , "{}" ) ;
35
43
} ) ;
36
44
37
45
it ( "should send a failure message to Sentry because no argument is passed in argv[2] (serializedEvent)" , async ( ) => {
38
- delete process . argv [ 2 ] ;
46
+ await spawnDetachedSubProcess ( SUBPROCESS_FILE_PATH , [ ] , {
47
+ HARDHAT_TEST_SUBPROCESS_RESULT_PATH : RESULT_FILE_PATH ,
48
+ } ) ;
39
49
40
- await main ( ) ;
41
50
await checkIfSubprocessWasExecuted ( RESULT_FILE_PATH ) ;
42
51
const fileRes = await readUtf8File ( RESULT_FILE_PATH ) ;
43
52
@@ -48,9 +57,10 @@ describe("sentry-subprocess", function () {
48
57
} ) ;
49
58
50
59
it ( "should send a failure message to Sentry because the argument in argv[2] is not a valid JSON" , async ( ) => {
51
- process . argv [ 2 ] = "not a valid JSON" ;
60
+ await spawnDetachedSubProcess ( SUBPROCESS_FILE_PATH , [ "not a valid JSON" ] , {
61
+ HARDHAT_TEST_SUBPROCESS_RESULT_PATH : RESULT_FILE_PATH ,
62
+ } ) ;
52
63
53
- await main ( ) ;
54
64
await checkIfSubprocessWasExecuted ( RESULT_FILE_PATH ) ;
55
65
const fileRes = await readUtf8File ( RESULT_FILE_PATH ) ;
56
66
@@ -61,9 +71,10 @@ describe("sentry-subprocess", function () {
61
71
} ) ;
62
72
63
73
it ( "should send a failure message to Sentry because there is an anonymization error" , async ( ) => {
64
- process . argv [ 2 ] = "null" ;
74
+ await spawnDetachedSubProcess ( SUBPROCESS_FILE_PATH , [ "null" ] , {
75
+ HARDHAT_TEST_SUBPROCESS_RESULT_PATH : RESULT_FILE_PATH ,
76
+ } ) ;
65
77
66
- await main ( ) ;
67
78
await checkIfSubprocessWasExecuted ( RESULT_FILE_PATH ) ;
68
79
const fileRes = await readUtf8File ( RESULT_FILE_PATH ) ;
69
80
0 commit comments