@joystick.js/cli-canary 0.0.0-canary.117 → 0.0.0-canary.119

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.
@@ -62,6 +62,7 @@ const handleSignalEvents = (processIds = [], nodeMajorVersion = 0, __dirname = "
62
62
  silent: true
63
63
  }
64
64
  );
65
+ process.cleanupProcess = cleanupProcess;
65
66
  process.on("SIGINT", async () => {
66
67
  const databaseProcessIds = getDatabaseProcessIds();
67
68
  cleanupProcess.send(JSON.stringify({ processIds: [...processIds, ...databaseProcessIds] }));
@@ -72,10 +73,6 @@ const handleSignalEvents = (processIds = [], nodeMajorVersion = 0, __dirname = "
72
73
  cleanupProcess.send(JSON.stringify({ processIds: [...processIds, ...databaseProcessIds] }));
73
74
  process.exit();
74
75
  });
75
- process.on("exit", async () => {
76
- const databaseProcessIds = getDatabaseProcessIds();
77
- cleanupProcess.send(JSON.stringify({ processIds: [...processIds, ...databaseProcessIds] }));
78
- });
79
76
  } catch (exception) {
80
77
  throw new Error(`[dev.handleSignalEvents] ${exception.message}`);
81
78
  }
@@ -517,8 +514,14 @@ const dev = async (options, { resolve, reject }) => {
517
514
  );
518
515
  if (options?.environment === "test") {
519
516
  process.loader.stop();
517
+ const databaseProcessIds = getDatabaseProcessIds();
520
518
  await runTests({
521
- __dirname
519
+ __dirname,
520
+ processIds: [
521
+ ...processIds,
522
+ ...databaseProcessIds
523
+ ],
524
+ cleanupProcess: process.cleanupProcess
522
525
  });
523
526
  }
524
527
  resolve();
@@ -1,6 +1,6 @@
1
1
  import child_process from "child_process";
2
2
  import CLILog from "../CLILog.js";
3
- const handleAvaSTDERR = (stderr = "") => {
3
+ const handleAvaSTDERR = (stderr = "", options = {}) => {
4
4
  try {
5
5
  console.log("STDERR", stderr);
6
6
  if (stderr?.includes("Using configuration")) {
@@ -16,7 +16,7 @@ const handleAvaSTDERR = (stderr = "") => {
16
16
  throw new Error(`[actionName.handleAvaSTDERR] ${exception.message}`);
17
17
  }
18
18
  };
19
- const handleAvaSTDOUT = (stdout = "") => {
19
+ const handleAvaSTDOUT = (stdout = "", options = {}) => {
20
20
  try {
21
21
  if (stdout?.includes("Using configuration")) {
22
22
  return null;
@@ -26,39 +26,41 @@ const handleAvaSTDOUT = (stdout = "") => {
26
26
  level: "danger",
27
27
  docs: "https://cheatcode.co/docs/joystick/test/setup"
28
28
  });
29
+ options.cleanupProcess.send(JSON.stringify({ processIds: options?.processIds }));
29
30
  return process.exit(0);
30
31
  }
31
32
  } catch (exception) {
32
33
  throw new Error(`[actionName.handleAvaSTDOUT] ${exception.message}`);
33
34
  }
34
35
  };
35
- const handleAvaSTDIO = (ava = {}) => {
36
+ const handleAvaSTDIO = (ava = {}, options = {}) => {
36
37
  try {
37
38
  ava.stdout.on("data", function(data) {
38
39
  const string = data.toString();
39
- handleAvaSTDOUT(string);
40
+ handleAvaSTDOUT(string, options);
40
41
  });
41
42
  ava.stderr.on("data", function(data) {
42
43
  const string = data.toString();
43
- handleAvaSTDERR(string);
44
+ handleAvaSTDERR(string, options);
44
45
  });
45
46
  } catch (exception) {
46
47
  throw new Error(`[runTests.handleAvaSTDIO] ${exception.message}`);
47
48
  }
48
49
  };
49
- const runAva = (__dirname = "") => {
50
+ const runAva = (options = {}) => {
50
51
  try {
51
- const packageRoot = __dirname?.split("/dist")[0];
52
+ const packageRoot = options?.__dirname?.split("/dist")[0];
52
53
  const avaPath = `${packageRoot}/node_modules/.bin/ava`;
54
+ console.log(process.cwd());
53
55
  return new Promise((resolve, reject) => {
54
- const ava = child_process.exec(`${avaPath} --config ${__dirname}/tests.config.js`, {
56
+ const ava = child_process.exec(`${avaPath} --config ${options?.__dirname}/tests.config.js`, {
55
57
  stdio: "inherit",
56
58
  env: {
57
59
  ...process.env,
58
60
  FORCE_COLOR: "1"
59
61
  }
60
62
  });
61
- handleAvaSTDIO(ava);
63
+ handleAvaSTDIO(ava, options);
62
64
  });
63
65
  } catch (exception) {
64
66
  throw new Error(`[runTests.runAva] ${exception.message}`);
@@ -77,7 +79,7 @@ const validateOptions = (options) => {
77
79
  const runTests = async (options, { resolve, reject }) => {
78
80
  try {
79
81
  validateOptions(options);
80
- await runAva(options?.__dirname);
82
+ await runAva(options);
81
83
  resolve();
82
84
  } catch (exception) {
83
85
  reject(`[runTests] ${exception.message}`);
@@ -1,4 +1,3 @@
1
- console.log(process.cwd());
2
1
  var tests_config_default = {
3
2
  files: ["tests/**/*"]
4
3
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joystick.js/cli-canary",
3
- "version": "0.0.0-canary.117",
3
+ "version": "0.0.0-canary.119",
4
4
  "type": "module",
5
5
  "description": "CLI for the Joystick JavaScript framework.",
6
6
  "main": "development.js",
@@ -75,6 +75,8 @@ const handleSignalEvents = (processIds = [], nodeMajorVersion = 0, __dirname = '
75
75
  }
76
76
  );
77
77
 
78
+ process.cleanupProcess = cleanupProcess;
79
+
78
80
  process.on("SIGINT", async () => {
79
81
  const databaseProcessIds = getDatabaseProcessIds();
80
82
  cleanupProcess.send(JSON.stringify(({ processIds: [...processIds, ...databaseProcessIds] })));
@@ -86,11 +88,6 @@ const handleSignalEvents = (processIds = [], nodeMajorVersion = 0, __dirname = '
86
88
  cleanupProcess.send(JSON.stringify(({ processIds: [...processIds, ...databaseProcessIds] })));
87
89
  process.exit();
88
90
  });
89
-
90
- process.on("exit", async () => {
91
- const databaseProcessIds = getDatabaseProcessIds();
92
- cleanupProcess.send(JSON.stringify(({ processIds: [...processIds, ...databaseProcessIds] })));
93
- });
94
91
  } catch (exception) {
95
92
  throw new Error(`[dev.handleSignalEvents] ${exception.message}`);
96
93
  }
@@ -621,8 +618,15 @@ const dev = async (options, { resolve, reject }) => {
621
618
 
622
619
  if (options?.environment === 'test') {
623
620
  process.loader.stop();
621
+ const databaseProcessIds = getDatabaseProcessIds();
622
+
624
623
  await runTests({
625
624
  __dirname,
625
+ processIds: [
626
+ ...processIds,
627
+ ...databaseProcessIds,
628
+ ],
629
+ cleanupProcess: process.cleanupProcess,
626
630
  });
627
631
  }
628
632
 
@@ -1,7 +1,7 @@
1
1
  import child_process from "child_process";
2
2
  import CLILog from "../CLILog.js";
3
3
 
4
- const handleAvaSTDERR = (stderr = '') => {
4
+ const handleAvaSTDERR = (stderr = '', options = {}) => {
5
5
  try {
6
6
  console.log('STDERR', stderr);
7
7
 
@@ -21,7 +21,7 @@ const handleAvaSTDERR = (stderr = '') => {
21
21
  }
22
22
  };
23
23
 
24
- const handleAvaSTDOUT = (stdout = '') => {
24
+ const handleAvaSTDOUT = (stdout = '', options = {}) => {
25
25
  try {
26
26
  // NOTE: Squash output about using a configuration file (we always do in the framework).
27
27
  if (stdout?.includes('Using configuration')) {
@@ -34,6 +34,10 @@ const handleAvaSTDOUT = (stdout = '') => {
34
34
  docs: 'https://cheatcode.co/docs/joystick/test/setup',
35
35
  });
36
36
 
37
+ // NOTE: Do this here because the standard SIGINT and SIGTERM hooks the dev process
38
+ // listens for don't catch a clean exit (and the process.exit() hook fires after exit).
39
+ options.cleanupProcess.send(JSON.stringify(({ processIds: options?.processIds })));
40
+
37
41
  return process.exit(0);
38
42
  }
39
43
  } catch (exception) {
@@ -41,32 +45,34 @@ const handleAvaSTDOUT = (stdout = '') => {
41
45
  }
42
46
  };
43
47
 
44
- const handleAvaSTDIO = (ava = {}) => {
48
+ const handleAvaSTDIO = (ava = {}, options = {}) => {
45
49
  try {
46
50
  ava.stdout.on('data', function (data) {
47
51
  const string = data.toString();
48
- handleAvaSTDOUT(string);
52
+ handleAvaSTDOUT(string, options);
49
53
  });
50
54
 
51
55
  ava.stderr.on('data', function (data) {
52
56
  const string = data.toString();
53
- handleAvaSTDERR(string);
57
+ handleAvaSTDERR(string, options);
54
58
  });
55
59
  } catch (exception) {
56
60
  throw new Error(`[runTests.handleAvaSTDIO] ${exception.message}`);
57
61
  }
58
62
  };
59
63
 
60
- const runAva = (__dirname = '') => {
64
+ const runAva = (options = {}) => {
61
65
  try {
62
66
  // NOTE: __dirname includes the entire path to lib/dev/index.js but we only
63
67
  // care about the root folder/package here (we need to reference the node_modules
64
68
  // folder in the package).
65
- const packageRoot = __dirname?.split('/dist')[0];
69
+ const packageRoot = options?.__dirname?.split('/dist')[0];
66
70
  const avaPath = `${packageRoot}/node_modules/.bin/ava`;
67
71
 
72
+ console.log(process.cwd());
73
+
68
74
  return new Promise((resolve, reject) => {
69
- const ava = child_process.exec(`${avaPath} --config ${__dirname}/tests.config.js`, {
75
+ const ava = child_process.exec(`${avaPath} --config ${options?.__dirname}/tests.config.js`, {
70
76
  stdio: 'inherit',
71
77
  env: {
72
78
  ...(process.env),
@@ -74,7 +80,7 @@ const runAva = (__dirname = '') => {
74
80
  }
75
81
  });
76
82
 
77
- handleAvaSTDIO(ava);
83
+ handleAvaSTDIO(ava, options);
78
84
  });
79
85
  } catch (exception) {
80
86
  throw new Error(`[runTests.runAva] ${exception.message}`);
@@ -94,7 +100,7 @@ const runTests = async (options, { resolve, reject }) => {
94
100
  try {
95
101
  validateOptions(options);
96
102
 
97
- await runAva(options?.__dirname);
103
+ await runAva(options);
98
104
 
99
105
  resolve();
100
106
  } catch (exception) {
@@ -1,5 +1,3 @@
1
- console.log(process.cwd());
2
-
3
1
  export default {
4
2
  files: ['tests/**/*']
5
3
  };