@memlab/e2e 1.0.22 → 1.0.24

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.
@@ -49,11 +49,28 @@ class NetworkManager {
49
49
  const requestCache = this.requestCache;
50
50
  yield session.send('Network.enable');
51
51
  yield session.send('Network.setRequestInterception', {
52
- patterns: patterns.map(pattern => ({
53
- urlPattern: pattern,
54
- resourceType: 'Script',
55
- interceptionStage: 'HeadersReceived',
56
- })),
52
+ // when extending the interception scope, make sure
53
+ // also update the resourceTypeToSuffix function in ScriptManager
54
+ patterns: [
55
+ // .js scripts
56
+ ...patterns.map(pattern => ({
57
+ urlPattern: pattern,
58
+ resourceType: 'Script',
59
+ interceptionStage: 'HeadersReceived',
60
+ })),
61
+ // .css stylesheets
62
+ ...patterns.map(pattern => ({
63
+ urlPattern: pattern,
64
+ resourceType: 'Stylesheet',
65
+ interceptionStage: 'HeadersReceived',
66
+ })),
67
+ // .html documents
68
+ ...patterns.map(pattern => ({
69
+ urlPattern: pattern,
70
+ resourceType: 'Document',
71
+ interceptionStage: 'HeadersReceived',
72
+ })),
73
+ ],
57
74
  });
58
75
  session.on('Network.requestIntercepted', ({ interceptionId, request, responseHeaders, resourceType }) => __awaiter(this, void 0, void 0, function* () {
59
76
  var _a;
@@ -87,7 +104,7 @@ class NetworkManager {
87
104
  this.networkLog(`Failed to process ${request.url} {interception id: ${interceptionId}}: ${e}`);
88
105
  }
89
106
  requestCache.set(response.body, newBody);
90
- this.scriptManager.logScript(request.url, newBody);
107
+ this.scriptManager.logScript(request.url, newBody, resourceType);
91
108
  }
92
109
  const newHeaders = [
93
110
  'Date: ' + new Date().toUTCString(),
@@ -22,7 +22,8 @@ export default class ScriptManager {
22
22
  loadCodeForUrl(url: string): Nullable<string>;
23
23
  getClosureScopeTreeForUrl(url: string): Nullable<ClosureScope>;
24
24
  rewriteScript(code: string, options?: RewriteScriptOption): Promise<string>;
25
- logScript(url: string, code: string): Promise<void>;
25
+ resourceTypeToSuffix(resourceType: string): string;
26
+ logScript(url: string, code: string, resourceType: string): Promise<void>;
26
27
  private debounce;
27
28
  }
28
29
  //# sourceMappingURL=ScriptManager.d.ts.map
@@ -96,17 +96,30 @@ class ScriptManager {
96
96
  return newCode;
97
97
  });
98
98
  }
99
- logScript(url, code) {
99
+ resourceTypeToSuffix(resourceType) {
100
+ switch (resourceType) {
101
+ case 'Script':
102
+ return '.js';
103
+ case 'Stylesheet':
104
+ return '.css';
105
+ case 'Document':
106
+ return '.html';
107
+ default:
108
+ return '.unknown';
109
+ }
110
+ }
111
+ logScript(url, code, resourceType) {
100
112
  return __awaiter(this, void 0, void 0, function* () {
101
113
  if (this.urlToScriptMap.has(url)) {
102
114
  return;
103
115
  }
104
116
  const metaFile = core_1.fileManager.getWebSourceMetaFile();
105
- const file = path_1.default.join(core_1.fileManager.getWebSourceDir(), `${++this.fileId}.js`);
117
+ const file = path_1.default.join(core_1.fileManager.getWebSourceDir(), `${++this.fileId}${this.resourceTypeToSuffix(resourceType)}`);
106
118
  const scriptInfo = {
107
119
  url,
108
120
  fileId: this.fileId,
109
121
  codePath: file,
122
+ resourceType,
110
123
  };
111
124
  this.urlToScriptMap.set(url, scriptInfo);
112
125
  this.scriptInfos.push(scriptInfo);
@@ -145,7 +145,7 @@ exceptionHandler = (_ex) => {
145
145
  ret = yield f.apply(self, args);
146
146
  }
147
147
  catch (ex) {
148
- exceptionHandler(core_2.utils.getError(ex));
148
+ yield exceptionHandler(core_2.utils.getError(ex));
149
149
  }
150
150
  return ret;
151
151
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memlab/e2e",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "license": "MIT",
5
5
  "description": "memlab browser E2E interaction libraries",
6
6
  "author": "Liang Gong <lgong@fb.com>",