jest-test-lineage-reporter 2.1.1 → 2.1.2
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/package.json +1 -1
- package/src/cli/commands/init.js +50 -10
package/package.json
CHANGED
package/src/cli/commands/init.js
CHANGED
|
@@ -22,6 +22,20 @@ async function initCommand(options) {
|
|
|
22
22
|
process.exit(1);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
// Detect if jest-test-lineage-reporter is installed locally or globally
|
|
26
|
+
const isLocalInstall = isInstalledLocally(cwd);
|
|
27
|
+
|
|
28
|
+
if (!isLocalInstall) {
|
|
29
|
+
warning('jest-test-lineage-reporter is installed globally.');
|
|
30
|
+
warning('For best results, install it locally in your project:\n');
|
|
31
|
+
console.log(' npm install --save-dev jest-test-lineage-reporter\n');
|
|
32
|
+
|
|
33
|
+
if (!options.force) {
|
|
34
|
+
error('Global installation detected. Use --force to continue with absolute paths.');
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
25
39
|
// Read package.json to check dependencies
|
|
26
40
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
27
41
|
const allDeps = {
|
|
@@ -51,8 +65,11 @@ async function initCommand(options) {
|
|
|
51
65
|
if (!options.force) {
|
|
52
66
|
warning(`jest.config.js already exists. Use --force to overwrite.`);
|
|
53
67
|
info('Please manually add the following to your jest.config.js:');
|
|
68
|
+
const setupPath = isLocalInstall
|
|
69
|
+
? 'jest-test-lineage-reporter/src/testSetup.js'
|
|
70
|
+
: getGlobalPackagePath('testSetup.js');
|
|
54
71
|
console.log(`
|
|
55
|
-
setupFilesAfterEnv: ['
|
|
72
|
+
setupFilesAfterEnv: ['${setupPath}'],
|
|
56
73
|
|
|
57
74
|
reporters: [
|
|
58
75
|
'default',
|
|
@@ -70,11 +87,11 @@ async function initCommand(options) {
|
|
|
70
87
|
},
|
|
71
88
|
`);
|
|
72
89
|
} else {
|
|
73
|
-
createJestConfig(jestConfigPath, options);
|
|
90
|
+
createJestConfig(jestConfigPath, options, isLocalInstall);
|
|
74
91
|
jestConfigCreated = true;
|
|
75
92
|
}
|
|
76
93
|
} else {
|
|
77
|
-
createJestConfig(jestConfigPath, options);
|
|
94
|
+
createJestConfig(jestConfigPath, options, isLocalInstall);
|
|
78
95
|
jestConfigCreated = true;
|
|
79
96
|
}
|
|
80
97
|
|
|
@@ -84,17 +101,20 @@ async function initCommand(options) {
|
|
|
84
101
|
if (!options.force) {
|
|
85
102
|
warning(`babel.config.js already exists. Use --force to overwrite.`);
|
|
86
103
|
info('Please manually add the lineage tracker plugin to your babel.config.js:');
|
|
104
|
+
const pluginPath = isLocalInstall
|
|
105
|
+
? 'jest-test-lineage-reporter/src/babel-plugin-lineage-tracker.js'
|
|
106
|
+
: getGlobalPackagePath('babel-plugin-lineage-tracker.js');
|
|
87
107
|
console.log(`
|
|
88
108
|
plugins: [
|
|
89
|
-
'
|
|
109
|
+
'${pluginPath}',
|
|
90
110
|
],
|
|
91
111
|
`);
|
|
92
112
|
} else {
|
|
93
|
-
createBabelConfig(babelConfigPath, options);
|
|
113
|
+
createBabelConfig(babelConfigPath, options, isLocalInstall);
|
|
94
114
|
babelConfigCreated = true;
|
|
95
115
|
}
|
|
96
116
|
} else {
|
|
97
|
-
createBabelConfig(babelConfigPath, options);
|
|
117
|
+
createBabelConfig(babelConfigPath, options, isLocalInstall);
|
|
98
118
|
babelConfigCreated = true;
|
|
99
119
|
}
|
|
100
120
|
|
|
@@ -137,14 +157,17 @@ async function initCommand(options) {
|
|
|
137
157
|
}
|
|
138
158
|
}
|
|
139
159
|
|
|
140
|
-
function createJestConfig(filePath, options) {
|
|
160
|
+
function createJestConfig(filePath, options, isLocalInstall) {
|
|
141
161
|
const isTypeScript = options.typescript || hasTypeScriptFiles();
|
|
162
|
+
const setupPath = isLocalInstall
|
|
163
|
+
? 'jest-test-lineage-reporter/src/testSetup.js'
|
|
164
|
+
: getGlobalPackagePath('testSetup.js');
|
|
142
165
|
|
|
143
166
|
const config = `module.exports = {
|
|
144
167
|
testEnvironment: 'node',
|
|
145
168
|
|
|
146
169
|
// Required: Setup file for lineage tracking
|
|
147
|
-
setupFilesAfterEnv: ['
|
|
170
|
+
setupFilesAfterEnv: ['${setupPath}'],
|
|
148
171
|
|
|
149
172
|
// Add the lineage reporter
|
|
150
173
|
reporters: [
|
|
@@ -179,8 +202,11 @@ function createJestConfig(filePath, options) {
|
|
|
179
202
|
fs.writeFileSync(filePath, config, 'utf8');
|
|
180
203
|
}
|
|
181
204
|
|
|
182
|
-
function createBabelConfig(filePath, options) {
|
|
205
|
+
function createBabelConfig(filePath, options, isLocalInstall) {
|
|
183
206
|
const isTypeScript = options.typescript || hasTypeScriptFiles();
|
|
207
|
+
const pluginPath = isLocalInstall
|
|
208
|
+
? 'jest-test-lineage-reporter/src/babel-plugin-lineage-tracker.js'
|
|
209
|
+
: getGlobalPackagePath('babel-plugin-lineage-tracker.js');
|
|
184
210
|
|
|
185
211
|
const config = `module.exports = {
|
|
186
212
|
presets: [
|
|
@@ -189,7 +215,7 @@ function createBabelConfig(filePath, options) {
|
|
|
189
215
|
],
|
|
190
216
|
plugins: [
|
|
191
217
|
// Required: Lineage tracker plugin for instrumentation
|
|
192
|
-
'
|
|
218
|
+
'${pluginPath}',
|
|
193
219
|
],
|
|
194
220
|
};
|
|
195
221
|
`;
|
|
@@ -211,4 +237,18 @@ function hasTypeScriptFiles() {
|
|
|
211
237
|
}
|
|
212
238
|
}
|
|
213
239
|
|
|
240
|
+
function isInstalledLocally(cwd) {
|
|
241
|
+
const localPath = path.join(cwd, 'node_modules', 'jest-test-lineage-reporter');
|
|
242
|
+
return fs.existsSync(localPath);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function getGlobalPackagePath(filename) {
|
|
246
|
+
// Get the directory where this script is running from
|
|
247
|
+
const scriptDir = path.dirname(path.dirname(path.dirname(__dirname)));
|
|
248
|
+
const srcPath = path.join(scriptDir, 'src', filename);
|
|
249
|
+
|
|
250
|
+
// Return absolute path
|
|
251
|
+
return srcPath;
|
|
252
|
+
}
|
|
253
|
+
|
|
214
254
|
module.exports = initCommand;
|