@teamscale/javascript-instrumenter 0.0.1-beta.11 → 0.0.1-beta.22

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/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ We use [Semantic Versioning](https://semver.org/).
2
+
3
+ # New Release
4
+
5
+ # 0.0.1-beta.21
6
+
7
+ - [fix] Include/exclude pattern and the paths to match were not normalized
8
+
9
+ # 0.0.1-beta.20
10
+
11
+ - [feature] Automatic release now for NPM packages and Docker images
package/README.md CHANGED
@@ -9,7 +9,7 @@ in the Teamscale Simple Coverage Format and sent to a Teamscale instance.
9
9
  The Teamscale JavaScript Profiler consists of the [Coverage Collector](https://www.npmjs.com/package/@teamscale/coverage-collector)
10
10
  and this JavaScript Instrumenter.
11
11
  More details on using them (in combination) can be found
12
- on the projects' [Github page](https://github.com/cqse/teamscale-javascript-profiler/).
12
+ in the [Teamscale Documentation](https://docs.teamscale.com/howto/recording-test-coverage-for-javascript/).
13
13
 
14
14
  The Instrumenter instruments a given (set of) JavaScript file(s) such that (1) coverage
15
15
  information is produced and (2) forwarded to the Collector.
@@ -25,28 +25,6 @@ yarn install
25
25
  yarn build
26
26
  ```
27
27
 
28
- ### Preparation: Source Maps
29
-
30
- Please make sure to enable the generation of source map files to ensure
31
- that the profiled code can be mapped back to the original.
32
-
33
- For example, when the tool Vite is used to bundle the code,
34
- the generation of source map information can be enabled by setting:
35
-
36
- ```
37
- build: {
38
- sourcemap: true
39
- }
40
- ```
41
-
42
- or
43
-
44
- ```
45
- build: {
46
- sourcemap: `inline`
47
- }
48
- ```
49
-
50
28
  ## Workflow Integration
51
29
 
52
30
  There are several options to run the Instrumenter. For example, via `yarn` by running
@@ -85,12 +63,8 @@ yarn instrumenter --inplace ./the/path/to/the/file.js --source-map ./the/path/to
85
63
  yarn instrumenter ./the/path/to/the/file.js --to ./the/file/path/to/write/to.js
86
64
  ```
87
65
 
88
- ### Integration with Testing Frameworks
89
-
90
- This is planned work: Provide a Babel plugin that provides a code transformation
91
- such that coverage information is collected and this information is forwarded.
92
-
93
66
  ## Limitations
94
67
 
95
68
  This tool inherits most of the limitations of IstanbulJs, including
96
69
  a considerable performance impact.
70
+
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamscale/javascript-instrumenter",
3
- "version": "0.0.1-beta.11",
3
+ "version": "0.0.1-beta.21",
4
4
  "description": "Istanbul-based coverage instrumenter with coverage forwarding via WebSockets",
5
5
  "main": "dist/src/main.js",
6
6
  "bin": "dist/src/main.js",
@@ -51,12 +51,19 @@ export declare class OriginSourcePattern {
51
51
  /**
52
52
  * Does the given pattern require to include the given set of files?
53
53
  *
54
+ * For example, a JavaScript bundle is compiled from several (origin) source files.
55
+ * If one of the files in the bundle is needed, then the full bundle is needed, that is,
56
+ * this function is required to return `true`.
57
+ *
54
58
  * @param originFiles - The file set to decide for include or exclude.
55
59
  *
56
- * @returns `true` if (1) all of the given files are supposed to be excluded,
57
- * or (2) if one of the files is supposed to be included.
60
+ * @returns `false` if (1) all given files are supposed to be excluded,
61
+ * or (2) `true` if at least one of the files is supposed to be included.
58
62
  */
59
63
  isAnyIncluded(originFiles: string[]): boolean;
64
+ private static normalizeGlobPattern;
65
+ private static normalizePath;
66
+ private static removeTrailingCurrentWorkingDir;
60
67
  }
61
68
  /**
62
69
  * The actual instrumentation task.
@@ -1 +1 @@
1
- {"version":3,"file":"Task.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/Task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAI/C;;GAEG;AACH,8BAAsB,kBAAkB;CAAG;AAE3C;;;GAGG;AACH,qBAAa,WAAW;IACvB,sBAAsB;IACtB,SAAgB,QAAQ,EAAE,MAAM,CAAC;IAEjC,2BAA2B;IAC3B,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,gEAAgE;IAChE,SAAgB,qB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AAM,CAAC;IAE5C,sDAAsD;IACtD,SAAgB,WAAW,EAAE,MAAM,CAAC;IAEpC,6DAA6D;IAC7D,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,+EAA+E;IAC/E,SAAgB,QAAQ,EAAE,MAAM,CAAC;gBAGhC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,mBAAmB,EAAE,MAAM,EAC3B,mBAAmB,EAAE,MAAM,EAC3B,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM;IAkBjB;;;;OAIG;IACI,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU;IAYnD;;OAEG;WACW,OAAO,IAAI,UAAU;IAInC;;;;OAIG;WACW,KAAK,CAAC,CAAC,EAAE,KAAK,GAAG,UAAU;IAKzC;;;;OAIG;WACW,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU;CAI9C;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,kBAAkB;IAC7D,2CAA2C;IAC3C,SAAgB,iBAAiB,EAAE,MAAM,CAAC;gBAE9B,iBAAiB,EAAE,MAAM;CAIrC"}
@@ -18,11 +18,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
21
24
  Object.defineProperty(exports, "__esModule", { value: true });
22
25
  exports.SourceMapFileReference = exports.TaskResult = exports.InstrumentationTask = exports.OriginSourcePattern = exports.CollectorSpecifier = exports.TaskElement = exports.SourceMapReference = void 0;
23
26
  const typescript_optional_1 = require("typescript-optional");
24
27
  const commons_1 = require("@cqse/commons");
25
28
  const matching = __importStar(require("micromatch"));
29
+ const path_1 = __importDefault(require("path"));
26
30
  /**
27
31
  * An abstract source map type.
28
32
  */
@@ -70,31 +74,52 @@ exports.CollectorSpecifier = CollectorSpecifier;
70
74
  */
71
75
  class OriginSourcePattern {
72
76
  constructor(include, exclude) {
73
- this.include = include;
74
- this.exclude = exclude;
77
+ this.include = OriginSourcePattern.normalizeGlobPattern(include);
78
+ this.exclude = OriginSourcePattern.normalizeGlobPattern(exclude);
75
79
  }
76
80
  /**
77
81
  * Does the given pattern require to include the given set of files?
78
82
  *
83
+ * For example, a JavaScript bundle is compiled from several (origin) source files.
84
+ * If one of the files in the bundle is needed, then the full bundle is needed, that is,
85
+ * this function is required to return `true`.
86
+ *
79
87
  * @param originFiles - The file set to decide for include or exclude.
80
88
  *
81
- * @returns `true` if (1) all of the given files are supposed to be excluded,
82
- * or (2) if one of the files is supposed to be included.
89
+ * @returns `false` if (1) all given files are supposed to be excluded,
90
+ * or (2) `true` if at least one of the files is supposed to be included.
83
91
  */
84
92
  isAnyIncluded(originFiles) {
85
93
  var _a;
94
+ const normalizedOriginFiles = originFiles.map(OriginSourcePattern.normalizePath);
86
95
  if (this.exclude) {
87
- const matchedToExclude = matching.match(originFiles, this.exclude);
96
+ const matchedToExclude = matching.match(normalizedOriginFiles, this.exclude);
88
97
  if (originFiles.length === matchedToExclude.length) {
89
98
  return false;
90
99
  }
91
100
  }
92
101
  if (this.include) {
93
- const matchedToInclude = matching.match(originFiles, (_a = this.include) !== null && _a !== void 0 ? _a : '**');
102
+ const matchedToInclude = matching.match(normalizedOriginFiles, (_a = this.include) !== null && _a !== void 0 ? _a : '**');
94
103
  return matchedToInclude.length > 0;
95
104
  }
96
105
  return true;
97
106
  }
107
+ static normalizeGlobPattern(pattern) {
108
+ if (!pattern) {
109
+ return pattern;
110
+ }
111
+ return OriginSourcePattern.removeTrailingCurrentWorkingDir(pattern);
112
+ }
113
+ static normalizePath(toNormalize) {
114
+ return OriginSourcePattern.removeTrailingCurrentWorkingDir(toNormalize);
115
+ }
116
+ static removeTrailingCurrentWorkingDir(removeFrom) {
117
+ const prefixToRemove = '.' + path_1.default.sep;
118
+ if (removeFrom.startsWith(prefixToRemove)) {
119
+ return removeFrom.substring(2);
120
+ }
121
+ return removeFrom;
122
+ }
98
123
  }
99
124
  exports.OriginSourcePattern = OriginSourcePattern;
100
125
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamscale/javascript-instrumenter",
3
- "version": "0.0.1-beta.11",
3
+ "version": "0.0.1-beta.22",
4
4
  "description": "Istanbul-based coverage instrumenter with coverage forwarding via WebSockets",
5
5
  "main": "dist/src/main.js",
6
6
  "bin": "dist/src/main.js",