Skip to content

Commit dace298

Browse files
authored
Merge pull request #105 from nodecraft/refactor/tests
2 parents d0cca17 + c7f995b commit dace298

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+4028
-3901
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/**
22
build/**
3+
coverage/**
34
test/json/**

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ jobs:
77
strategy:
88
matrix:
99
os: [ubuntu-latest, windows-latest, macOS-latest]
10-
node: [20, 22]
10+
node: [22, 24]
1111
name: Node ${{ matrix.node }} ${{ matrix.os }} Test
1212
steps:
13-
- uses: actions/checkout@v4
13+
- uses: actions/checkout@v5
1414
- name: Setup node
15-
uses: actions/setup-node@v4
15+
uses: actions/setup-node@v5
1616
with:
1717
node-version: ${{ matrix.node }}
1818
cache: "npm"

.mocharc.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

lib/spawnpoint.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,23 @@ const helpers = require('./helpers.js');
2626
class spawnpoint extends EventEmitter {
2727
/**
2828
* Creates new instance of spawnpoint
29-
* @param {string} [configFile] Sets the JSON file spawnpoint uses to setup the framework.
29+
* @param {string|Object} [configFile] Sets the JSON file spawnpoint uses to setup the framework, or an options object.
30+
* @param {string} [configFile.configFile='/config/app.json'] Path to the config file when using options object.
31+
* @param {string} [configFile.cwd=process.cwd()] Working directory for the applicationndash avoids needing process.chdir().
3032
* @return {this}
3133
*/
3234
constructor(configFile = '/config/app.json') {
3335
// init EventEmitter
3436
super();
3537

36-
if (typeof(configFile) !== 'string') {
38+
// Support options object for more flexibility
39+
let options = {};
40+
if (typeof configFile === 'object' && configFile !== null && !Array.isArray(configFile)) {
41+
options = configFile;
42+
configFile = options.configFile || '/config/app.json';
43+
}
44+
45+
if (typeof configFile !== 'string') {
3746
throw new TypeError('`configFile` must be a path string to a Spawnpoint config file.');
3847
}
3948
if (!configFile.endsWith('.json') && !configFile.endsWith('.js')) {
@@ -51,8 +60,8 @@ class spawnpoint extends EventEmitter {
5160
stopAttempts: 0, // how many attempts to stop have been triggered
5261
};
5362

54-
// app CWD
55-
this.cwd = process.cwd();
63+
// app CWD - can be passed via options to avoid process.chdir()
64+
this.cwd = options.cwd || process.cwd();
5665

5766
// detect if we are in a container (lazy-loaded on first access)
5867
this._containerized = null;
@@ -283,6 +292,8 @@ class spawnpoint extends EventEmitter {
283292
if (typeof(exts) === 'string') {
284293
exts = [exts];
285294
}
295+
// normalize path separators for cross-platform support
296+
dir = dir.replaceAll('\\', '/');
286297
const list = [];
287298
let stat;
288299
try {
@@ -293,8 +304,8 @@ class spawnpoint extends EventEmitter {
293304
if (!stat || !stat.isDirectory()) {
294305
return list;
295306
}
296-
// ensure proper trailing slash and normalize path separators
297-
dir = String(dir + '/').replaceAll('\\', '/');
307+
// ensure proper trailing slash
308+
dir = String(dir + '/');
298309

299310
// Use withFileTypes to avoid a stat for every entry (significantly faster)
300311
const stack = [dir];

0 commit comments

Comments
 (0)