fragment-ts 1.0.20 → 1.0.21
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.
- package/dist/cli/commands/init.command.js +1 -1
- package/dist/cli/commands/test.command.d.ts.map +1 -1
- package/dist/cli/commands/test.command.js +42 -75
- package/dist/cli/commands/test.command.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/commands/init.command.ts +1 -1
- package/src/cli/commands/test.command.ts +57 -79
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test.command.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/test.command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"test.command.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/test.command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,qBAAa,WAAW;IACtB,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;mBAkBlB,QAAQ;IAkJ7B,OAAO,CAAC,MAAM,CAAC,oBAAoB;CA6GpC"}
|
|
@@ -41,6 +41,7 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
41
41
|
const path = __importStar(require("path"));
|
|
42
42
|
const child_process_1 = require("child_process");
|
|
43
43
|
const fs = __importStar(require("fs"));
|
|
44
|
+
const chokidar_1 = __importDefault(require("chokidar"));
|
|
44
45
|
class TestCommand {
|
|
45
46
|
static register(program) {
|
|
46
47
|
program
|
|
@@ -122,52 +123,45 @@ class TestCommand {
|
|
|
122
123
|
const scriptPath = path.join(cwd, ".fragment-test-runner.js");
|
|
123
124
|
try {
|
|
124
125
|
fs.writeFileSync(scriptPath, scriptContent);
|
|
125
|
-
// Make the script executable
|
|
126
126
|
fs.chmodSync(scriptPath, "755");
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
TS_NODE_TRANSPILE_ONLY: "true",
|
|
131
|
-
NODE_ENV: "test",
|
|
132
|
-
// Only set TS_NODE_PROJECT if tsconfig exists
|
|
133
|
-
...(hasTsConfig && useTypeScript
|
|
134
|
-
? { TS_NODE_PROJECT: tsConfigPath }
|
|
135
|
-
: {}),
|
|
136
|
-
// Handle color output
|
|
137
|
-
FORCE_COLOR: options.color === false ? "0" : "1",
|
|
138
|
-
};
|
|
139
|
-
// Add --watch support
|
|
127
|
+
// -----------------------
|
|
128
|
+
// Watch / Coverage / Single Run
|
|
129
|
+
// -----------------------
|
|
140
130
|
if (options.watch) {
|
|
141
|
-
console.log(chalk_1.default.
|
|
131
|
+
console.log(chalk_1.default.green("\n👀 Watch mode enabled. Listening for changes...\n"));
|
|
132
|
+
const watcher = chokidar_1.default.watch(`${basePath}/**/*.spec.${useTypeScript ? "ts" : "js"}`, {
|
|
133
|
+
ignoreInitial: true,
|
|
134
|
+
});
|
|
135
|
+
const runTests = () => {
|
|
136
|
+
const proc = (0, child_process_1.spawn)("node", [scriptPath], { stdio: "inherit" });
|
|
137
|
+
proc.on("close", (code) => {
|
|
138
|
+
if (code !== 0)
|
|
139
|
+
console.log(chalk_1.default.red(`Test run exited with code ${code}`));
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
runTests(); // Initial run
|
|
143
|
+
watcher.on("all", (event, pathChanged) => {
|
|
144
|
+
console.log(chalk_1.default.blue(`\n🔄 File changed (${event}): ${pathChanged}`));
|
|
145
|
+
runTests();
|
|
146
|
+
});
|
|
142
147
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
148
|
+
else if (options.coverage) {
|
|
149
|
+
console.log(chalk_1.default.green("\n📊 Coverage enabled. Running tests with coverage...\n"));
|
|
150
|
+
const proc = (0, child_process_1.spawn)("npx", ["c8", "--reporter=lcov", "--reporter=text", "node", scriptPath], { stdio: "inherit" });
|
|
151
|
+
proc.on("close", (code) => process.exit(code || 0));
|
|
152
|
+
proc.on("error", (err) => {
|
|
153
|
+
console.error(chalk_1.default.red("Failed to run coverage:"), err);
|
|
154
|
+
process.exit(1);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
const proc = (0, child_process_1.spawn)("node", [scriptPath], { stdio: "inherit" });
|
|
159
|
+
proc.on("close", (code) => process.exit(code || 0));
|
|
160
|
+
proc.on("error", (err) => {
|
|
161
|
+
console.error(chalk_1.default.red("Failed to run tests:"), err);
|
|
162
|
+
process.exit(1);
|
|
163
|
+
});
|
|
146
164
|
}
|
|
147
|
-
const proc = (0, child_process_1.spawn)("node", nodeArgs, {
|
|
148
|
-
cwd,
|
|
149
|
-
stdio: "inherit",
|
|
150
|
-
env,
|
|
151
|
-
});
|
|
152
|
-
proc.on("close", (code) => {
|
|
153
|
-
try {
|
|
154
|
-
fs.unlinkSync(scriptPath);
|
|
155
|
-
}
|
|
156
|
-
catch (e) {
|
|
157
|
-
// Ignore cleanup errors
|
|
158
|
-
}
|
|
159
|
-
process.exit(code || 0);
|
|
160
|
-
});
|
|
161
|
-
proc.on("error", (error) => {
|
|
162
|
-
console.error(chalk_1.default.red("Failed to run tests:"), error);
|
|
163
|
-
try {
|
|
164
|
-
fs.unlinkSync(scriptPath);
|
|
165
|
-
}
|
|
166
|
-
catch (e) {
|
|
167
|
-
// Ignore cleanup errors
|
|
168
|
-
}
|
|
169
|
-
process.exit(1);
|
|
170
|
-
});
|
|
171
165
|
}
|
|
172
166
|
catch (error) {
|
|
173
167
|
console.error(chalk_1.default.red("Failed to create test runner:"), error.message);
|
|
@@ -176,14 +170,11 @@ class TestCommand {
|
|
|
176
170
|
}
|
|
177
171
|
static generateRunnerScript(options) {
|
|
178
172
|
const { useTypeScript, basePath, pattern, hasTsConfig, tsConfigPath, noColor, } = options;
|
|
179
|
-
|
|
180
|
-
// This assumes the test runner is installed as a dependency
|
|
181
|
-
let runnerImportPath = "fragment-ts/testing";
|
|
182
|
-
// Try to find the local test runner first for development
|
|
173
|
+
let runnerImportPath = "fragment-ts";
|
|
183
174
|
const possiblePaths = [
|
|
184
175
|
path.join(process.cwd(), "node_modules", "fragment-ts", "testing"),
|
|
185
176
|
path.join(process.cwd(), "node_modules", "fragment-ts", "dist", "testing"),
|
|
186
|
-
path.join(__dirname, "..", "..", "testing"),
|
|
177
|
+
path.join(__dirname, "..", "..", "testing"),
|
|
187
178
|
];
|
|
188
179
|
let resolvedRunnerPath = runnerImportPath;
|
|
189
180
|
for (const testPath of possiblePaths) {
|
|
@@ -198,11 +189,9 @@ class TestCommand {
|
|
|
198
189
|
${useTypeScript ? "require('ts-node/register/transpile-only');" : ""}
|
|
199
190
|
require('reflect-metadata');
|
|
200
191
|
|
|
201
|
-
// Set environment
|
|
202
192
|
process.env.NODE_ENV = 'test';
|
|
203
193
|
${noColor ? "process.env.FORCE_COLOR = '0';" : "process.env.FORCE_COLOR = '1';"}
|
|
204
194
|
|
|
205
|
-
// Set up TypeScript config if available
|
|
206
195
|
${hasTsConfig && useTypeScript
|
|
207
196
|
? `
|
|
208
197
|
try {
|
|
@@ -217,17 +206,13 @@ try {
|
|
|
217
206
|
skipLibCheck: true
|
|
218
207
|
}
|
|
219
208
|
});
|
|
220
|
-
} catch (error) {
|
|
221
|
-
// Ignore, ts-node might not be available
|
|
222
|
-
}`
|
|
209
|
+
} catch (error) {}`
|
|
223
210
|
: ""}
|
|
224
211
|
|
|
225
212
|
let testRunner;
|
|
226
213
|
try {
|
|
227
|
-
// Try to import the test runner
|
|
228
214
|
const testModule = require('${resolvedRunnerPath}');
|
|
229
215
|
|
|
230
|
-
// Handle different export patterns
|
|
231
216
|
if (testModule.getTestRunner) {
|
|
232
217
|
testRunner = testModule.getTestRunner();
|
|
233
218
|
} else if (testModule.TestRunner) {
|
|
@@ -235,7 +220,6 @@ try {
|
|
|
235
220
|
} else if (testModule.default && testModule.default.getTestRunner) {
|
|
236
221
|
testRunner = testModule.default.getTestRunner();
|
|
237
222
|
} else {
|
|
238
|
-
// Fallback to creating a new instance
|
|
239
223
|
testRunner = testModule;
|
|
240
224
|
}
|
|
241
225
|
} catch (error) {
|
|
@@ -247,35 +231,18 @@ try {
|
|
|
247
231
|
async function runTests() {
|
|
248
232
|
try {
|
|
249
233
|
console.log('Looking for test files...');
|
|
250
|
-
|
|
251
|
-
// Load test files with the runner
|
|
252
234
|
await testRunner.loadTestFiles('${basePath}/${pattern}');
|
|
253
|
-
|
|
254
|
-
// Run tests
|
|
255
235
|
await testRunner.run();
|
|
256
236
|
} catch (error) {
|
|
257
237
|
console.error('\\n❌ Error running tests:', error.message);
|
|
258
|
-
|
|
259
|
-
if (error.stack && process.env.DEBUG) {
|
|
260
|
-
console.error(error.stack);
|
|
261
|
-
}
|
|
262
|
-
|
|
238
|
+
if (error.stack && process.env.DEBUG) console.error(error.stack);
|
|
263
239
|
process.exit(1);
|
|
264
240
|
}
|
|
265
241
|
}
|
|
266
242
|
|
|
267
|
-
|
|
268
|
-
process.on('
|
|
269
|
-
console.log('\\n\\nTest run interrupted');
|
|
270
|
-
process.exit(130);
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
process.on('SIGTERM', () => {
|
|
274
|
-
console.log('\\n\\nTest run terminated');
|
|
275
|
-
process.exit(143);
|
|
276
|
-
});
|
|
243
|
+
process.on('SIGINT', () => { console.log('\\n\\nTest run interrupted'); process.exit(130); });
|
|
244
|
+
process.on('SIGTERM', () => { console.log('\\n\\nTest run terminated'); process.exit(143); });
|
|
277
245
|
|
|
278
|
-
// Run the tests
|
|
279
246
|
runTests().catch(error => {
|
|
280
247
|
console.error('Unhandled error:', error);
|
|
281
248
|
process.exit(1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test.command.js","sourceRoot":"","sources":["../../../src/cli/commands/test.command.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kDAA0B;AAC1B,2CAA6B;AAC7B,iDAAsC;AACtC,uCAAyB;
|
|
1
|
+
{"version":3,"file":"test.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GAAG,EAAE,EACb,cAAc,EACd,aAAa,EACb,MAAM,EACN,SAAS,CACV;YACD,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC;SAC5C,CAAC;QAEF,IAAI,kBAAkB,GAAG,gBAAgB,CAAC;QAC1C,KAAK,MAAM,QAAQ,IAAI,aAAa,EAAE,CAAC;YACrC,IAAI,EAAE,CAAC,UAAU,CAAC,QAAQ,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,QAAQ,GAAG,KAAK,CAAC,EAAE,CAAC;gBACvE,kBAAkB,GAAG,QAAQ,CAAC;gBAC9B,MAAM;YACR,CAAC;QACH,CAAC;QAED,OAAO;;;EAGT,aAAa,CAAC,CAAC,CAAC,6CAA6C,CAAC,CAAC,CAAC,EAAE;;;;EAIlE,OAAO,CAAC,CAAC,CAAC,gCAAgC,CAAC,CAAC,CAAC,gCAAgC;;EAG7E,WAAW,IAAI,aAAa;YAC1B,CAAC,CAAC;;;;gBAIU,YAAY;;;;;;;;;mBAST;YACf,CAAC,CAAC,EACN;;;;gCAIgC,kBAAkB;;;;;;;;;;;;;;;;;;;;sCAoBZ,QAAQ,IAAI,OAAO;;;;;;;;;;;;;;;;CAgBxD,CAAC;IACA,CAAC;CACF;AAlRD,kCAkRC"}
|
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@ import chalk from "chalk";
|
|
|
3
3
|
import * as path from "path";
|
|
4
4
|
import { spawn } from "child_process";
|
|
5
5
|
import * as fs from "fs";
|
|
6
|
+
import chokidar from "chokidar";
|
|
6
7
|
|
|
7
8
|
export class TestCommand {
|
|
8
9
|
static register(program: Command): void {
|
|
@@ -102,63 +103,67 @@ export class TestCommand {
|
|
|
102
103
|
|
|
103
104
|
try {
|
|
104
105
|
fs.writeFileSync(scriptPath, scriptContent);
|
|
105
|
-
|
|
106
|
-
// Make the script executable
|
|
107
106
|
fs.chmodSync(scriptPath, "755");
|
|
108
107
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
TS_NODE_TRANSPILE_ONLY: "true",
|
|
113
|
-
NODE_ENV: "test",
|
|
114
|
-
// Only set TS_NODE_PROJECT if tsconfig exists
|
|
115
|
-
...(hasTsConfig && useTypeScript
|
|
116
|
-
? { TS_NODE_PROJECT: tsConfigPath }
|
|
117
|
-
: {}),
|
|
118
|
-
// Handle color output
|
|
119
|
-
FORCE_COLOR: options.color === false ? "0" : "1",
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
// Add --watch support
|
|
108
|
+
// -----------------------
|
|
109
|
+
// Watch / Coverage / Single Run
|
|
110
|
+
// -----------------------
|
|
123
111
|
if (options.watch) {
|
|
124
112
|
console.log(
|
|
125
|
-
chalk.
|
|
126
|
-
"\n⚠️ Watch mode is not yet implemented. Running once.\n",
|
|
127
|
-
),
|
|
113
|
+
chalk.green("\n👀 Watch mode enabled. Listening for changes...\n"),
|
|
128
114
|
);
|
|
129
|
-
}
|
|
130
115
|
|
|
131
|
-
|
|
132
|
-
|
|
116
|
+
const watcher = chokidar.watch(
|
|
117
|
+
`${basePath}/**/*.spec.${useTypeScript ? "ts" : "js"}`,
|
|
118
|
+
{
|
|
119
|
+
ignoreInitial: true,
|
|
120
|
+
},
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
const runTests = () => {
|
|
124
|
+
const proc = spawn("node", [scriptPath], { stdio: "inherit" });
|
|
125
|
+
|
|
126
|
+
proc.on("close", (code) => {
|
|
127
|
+
if (code !== 0)
|
|
128
|
+
console.log(chalk.red(`Test run exited with code ${code}`));
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
runTests(); // Initial run
|
|
133
|
+
|
|
134
|
+
watcher.on("all", (event, pathChanged) => {
|
|
135
|
+
console.log(
|
|
136
|
+
chalk.blue(`\n🔄 File changed (${event}): ${pathChanged}`),
|
|
137
|
+
);
|
|
138
|
+
runTests();
|
|
139
|
+
});
|
|
140
|
+
} else if (options.coverage) {
|
|
133
141
|
console.log(
|
|
134
|
-
chalk.
|
|
142
|
+
chalk.green(
|
|
143
|
+
"\n📊 Coverage enabled. Running tests with coverage...\n",
|
|
144
|
+
),
|
|
135
145
|
);
|
|
136
|
-
}
|
|
137
146
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
147
|
+
const proc = spawn(
|
|
148
|
+
"npx",
|
|
149
|
+
["c8", "--reporter=lcov", "--reporter=text", "node", scriptPath],
|
|
150
|
+
{ stdio: "inherit" },
|
|
151
|
+
);
|
|
143
152
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
});
|
|
153
|
+
proc.on("close", (code) => process.exit(code || 0));
|
|
154
|
+
proc.on("error", (err) => {
|
|
155
|
+
console.error(chalk.red("Failed to run coverage:"), err);
|
|
156
|
+
process.exit(1);
|
|
157
|
+
});
|
|
158
|
+
} else {
|
|
159
|
+
const proc = spawn("node", [scriptPath], { stdio: "inherit" });
|
|
152
160
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
process.exit(1);
|
|
161
|
-
});
|
|
161
|
+
proc.on("close", (code) => process.exit(code || 0));
|
|
162
|
+
proc.on("error", (err) => {
|
|
163
|
+
console.error(chalk.red("Failed to run tests:"), err);
|
|
164
|
+
process.exit(1);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
162
167
|
} catch (error: any) {
|
|
163
168
|
console.error(chalk.red("Failed to create test runner:"), error.message);
|
|
164
169
|
process.exit(1);
|
|
@@ -184,11 +189,8 @@ export class TestCommand {
|
|
|
184
189
|
noColor,
|
|
185
190
|
} = options;
|
|
186
191
|
|
|
187
|
-
|
|
188
|
-
// This assumes the test runner is installed as a dependency
|
|
189
|
-
let runnerImportPath = "fragment-ts/testing";
|
|
192
|
+
let runnerImportPath = "fragment-ts";
|
|
190
193
|
|
|
191
|
-
// Try to find the local test runner first for development
|
|
192
194
|
const possiblePaths = [
|
|
193
195
|
path.join(process.cwd(), "node_modules", "fragment-ts", "testing"),
|
|
194
196
|
path.join(
|
|
@@ -198,7 +200,7 @@ export class TestCommand {
|
|
|
198
200
|
"dist",
|
|
199
201
|
"testing",
|
|
200
202
|
),
|
|
201
|
-
path.join(__dirname, "..", "..", "testing"),
|
|
203
|
+
path.join(__dirname, "..", "..", "testing"),
|
|
202
204
|
];
|
|
203
205
|
|
|
204
206
|
let resolvedRunnerPath = runnerImportPath;
|
|
@@ -215,11 +217,9 @@ export class TestCommand {
|
|
|
215
217
|
${useTypeScript ? "require('ts-node/register/transpile-only');" : ""}
|
|
216
218
|
require('reflect-metadata');
|
|
217
219
|
|
|
218
|
-
// Set environment
|
|
219
220
|
process.env.NODE_ENV = 'test';
|
|
220
221
|
${noColor ? "process.env.FORCE_COLOR = '0';" : "process.env.FORCE_COLOR = '1';"}
|
|
221
222
|
|
|
222
|
-
// Set up TypeScript config if available
|
|
223
223
|
${
|
|
224
224
|
hasTsConfig && useTypeScript
|
|
225
225
|
? `
|
|
@@ -235,18 +235,14 @@ try {
|
|
|
235
235
|
skipLibCheck: true
|
|
236
236
|
}
|
|
237
237
|
});
|
|
238
|
-
} catch (error) {
|
|
239
|
-
// Ignore, ts-node might not be available
|
|
240
|
-
}`
|
|
238
|
+
} catch (error) {}`
|
|
241
239
|
: ""
|
|
242
240
|
}
|
|
243
241
|
|
|
244
242
|
let testRunner;
|
|
245
243
|
try {
|
|
246
|
-
// Try to import the test runner
|
|
247
244
|
const testModule = require('${resolvedRunnerPath}');
|
|
248
245
|
|
|
249
|
-
// Handle different export patterns
|
|
250
246
|
if (testModule.getTestRunner) {
|
|
251
247
|
testRunner = testModule.getTestRunner();
|
|
252
248
|
} else if (testModule.TestRunner) {
|
|
@@ -254,7 +250,6 @@ try {
|
|
|
254
250
|
} else if (testModule.default && testModule.default.getTestRunner) {
|
|
255
251
|
testRunner = testModule.default.getTestRunner();
|
|
256
252
|
} else {
|
|
257
|
-
// Fallback to creating a new instance
|
|
258
253
|
testRunner = testModule;
|
|
259
254
|
}
|
|
260
255
|
} catch (error) {
|
|
@@ -266,35 +261,18 @@ try {
|
|
|
266
261
|
async function runTests() {
|
|
267
262
|
try {
|
|
268
263
|
console.log('Looking for test files...');
|
|
269
|
-
|
|
270
|
-
// Load test files with the runner
|
|
271
264
|
await testRunner.loadTestFiles('${basePath}/${pattern}');
|
|
272
|
-
|
|
273
|
-
// Run tests
|
|
274
265
|
await testRunner.run();
|
|
275
266
|
} catch (error) {
|
|
276
267
|
console.error('\\n❌ Error running tests:', error.message);
|
|
277
|
-
|
|
278
|
-
if (error.stack && process.env.DEBUG) {
|
|
279
|
-
console.error(error.stack);
|
|
280
|
-
}
|
|
281
|
-
|
|
268
|
+
if (error.stack && process.env.DEBUG) console.error(error.stack);
|
|
282
269
|
process.exit(1);
|
|
283
270
|
}
|
|
284
271
|
}
|
|
285
272
|
|
|
286
|
-
|
|
287
|
-
process.on('
|
|
288
|
-
console.log('\\n\\nTest run interrupted');
|
|
289
|
-
process.exit(130);
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
process.on('SIGTERM', () => {
|
|
293
|
-
console.log('\\n\\nTest run terminated');
|
|
294
|
-
process.exit(143);
|
|
295
|
-
});
|
|
273
|
+
process.on('SIGINT', () => { console.log('\\n\\nTest run interrupted'); process.exit(130); });
|
|
274
|
+
process.on('SIGTERM', () => { console.log('\\n\\nTest run terminated'); process.exit(143); });
|
|
296
275
|
|
|
297
|
-
// Run the tests
|
|
298
276
|
runTests().catch(error => {
|
|
299
277
|
console.error('Unhandled error:', error);
|
|
300
278
|
process.exit(1);
|