flake-monster 0.3.2 → 0.3.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flake-monster",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Source-to-source test hardener that injects async delays to surface flaky tests",
5
5
  "type": "module",
6
6
  "bin": {
@@ -405,13 +405,20 @@ export function computeRuntimeImportInsertion(ast, source, runtimeImportPath) {
405
405
  }
406
406
  }
407
407
 
408
- // Find the newline after the last import (or start of file)
409
- let insertOffset = lastImportEnd;
410
- while (insertOffset < source.length && source[insertOffset] !== '\n') {
411
- insertOffset++;
412
- }
413
- if (insertOffset < source.length) {
414
- insertOffset++; // past the \n
408
+ let insertOffset;
409
+ if (lastImportEnd === 0) {
410
+ // No existing imports insert at the very start of the file
411
+ // (not after the first line, which may be inside a block comment)
412
+ insertOffset = 0;
413
+ } else {
414
+ // Find the newline after the last import
415
+ insertOffset = lastImportEnd;
416
+ while (insertOffset < source.length && source[insertOffset] !== '\n') {
417
+ insertOffset++;
418
+ }
419
+ if (insertOffset < source.length) {
420
+ insertOffset++; // past the \n
421
+ }
415
422
  }
416
423
 
417
424
  const text = `import { ${DELAY_OBJECT} } from '${runtimeImportPath}';\n`;