• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use rollupObject file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { expect } from 'chai';
17import fs from 'fs';
18import mocha from 'mocha';
19import path from 'path';
20import sinon from 'sinon';
21
22import {
23  RELEASE
24} from '../../../lib/fast_build/ark_compiler/common/ark_define';
25import RollUpPluginMock from '../mock/rollup_mock/rollup_plugin_mock';
26import { SourceMapGenerator } from '../../../lib/fast_build/ark_compiler/generate_sourcemap';
27import {
28  ENTRYABILITY_JS_PATH_DEFAULT,
29  ENTRYABILITY_TS_PATH_DEFAULT,
30  ENTRY_PACKAGE_NAME_DEFAULT,
31  ENTRY_MODULE_VERSION_DEFAULT,
32  INDEX_ETS_PATH_DEFAULT,
33  INDEX_JS_CACHE_PATH
34} from '../mock/rollup_mock/common';
35import {
36  compilingEtsOrTsFiles,
37  hasTsNoCheckOrTsIgnoreFiles,
38  cleanUpFilesList
39} from '../../../lib/fast_build/ark_compiler/utils';
40import {
41  ArkTSInternalErrorDescription,
42  ErrorCode,
43} from '../../../lib/fast_build/ark_compiler/error_code';
44import {
45  CommonLogger,
46  LogData,
47  LogDataFactory
48} from '../../../lib/fast_build/ark_compiler/logger';
49
50const prefix = `${ENTRY_PACKAGE_NAME_DEFAULT}|${ENTRY_PACKAGE_NAME_DEFAULT}|${ENTRY_MODULE_VERSION_DEFAULT}|`;
51let entryPkgInfo = `${ENTRY_PACKAGE_NAME_DEFAULT}|${ENTRY_MODULE_VERSION_DEFAULT}`;
52
53mocha.describe('test generate_sourcemap api', function () {
54  mocha.before(function () {
55    this.rollup = new RollUpPluginMock();
56  });
57
58  mocha.after(() => {
59    delete this.rollup;
60  });
61
62  mocha.it('1-1: test getPkgInfoByModuleId under build debug', function () {
63    this.rollup.build();
64    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
65    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
66    let pkgInfo = sourceMapGenerator.getPkgInfoByModuleId(moduleId);
67
68    expect(pkgInfo && pkgInfo.entry && pkgInfo.modulePath && pkgInfo.entry.name && pkgInfo.entry.version !== '' && pkgInfo.entry.version != undefined).to.be.true;
69    SourceMapGenerator.cleanSourceMapObject();
70  });
71
72  mocha.it('1-2: test getPkgInfoByModuleId under build release', function () {
73    this.rollup.build(RELEASE);
74    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
75    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
76    let pkgInfo = sourceMapGenerator.getPkgInfoByModuleId(moduleId);
77
78    expect(pkgInfo && pkgInfo.entry && pkgInfo.modulePath && pkgInfo.entry.name && pkgInfo.entry.version !== '' && pkgInfo.entry.version != undefined).to.be.true;
79    SourceMapGenerator.cleanSourceMapObject();
80  });
81
82  mocha.it('1-3: test getPkgInfoByModuleId under preview', function () {
83    this.rollup.preview();
84    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
85    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
86    let pkgInfo = sourceMapGenerator.getPkgInfoByModuleId(moduleId);
87
88    expect(pkgInfo && pkgInfo.entry && pkgInfo.modulePath && pkgInfo.entry.name && pkgInfo.entry.version !== '' && pkgInfo.entry.version != undefined).to.be.true;
89    SourceMapGenerator.cleanSourceMapObject();
90  });
91
92  mocha.it('1-4: test getPkgInfoByModuleId under hotReload', function () {
93    this.rollup.hotReload();
94    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
95    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
96    let pkgInfo = sourceMapGenerator.getPkgInfoByModuleId(moduleId);
97
98    expect(pkgInfo && pkgInfo.entry && pkgInfo.modulePath && pkgInfo.entry.name && pkgInfo.entry.version !== '' && pkgInfo.entry.version != undefined).to.be.true;
99    SourceMapGenerator.cleanSourceMapObject();
100  });
101
102  mocha.it('1-5: test getPkgInfoByModuleId with file name obfuscate', function () {
103    this.rollup.build();
104    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
105    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
106    let pkgInfo = sourceMapGenerator.getPkgInfoByModuleId(moduleId, true);
107    expect(pkgInfo && pkgInfo.entry && pkgInfo.modulePath && pkgInfo.entry.name && pkgInfo.entry.version !== '' && pkgInfo.entry.version != undefined).to.be.true;
108    expect(pkgInfo.modulePath == 'src/main/a/b.js').to.be.true;
109    SourceMapGenerator.cleanSourceMapObject();
110  });
111
112  mocha.it('1-6: test GetModuleInfoFaild error of getPkgInfoByModuleId', function () {
113    this.rollup.build();
114    const errInfo: LogData = LogDataFactory.newInstance(
115      ErrorCode.ETS2BUNDLE_INTERNAL_GET_MODULE_INFO_FAILED,
116      ArkTSInternalErrorDescription,
117      'Failed to get ModuleInfo, moduleId: moduleId'
118    );
119    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
120    let moduleId = "moduleId";
121    const getModuleInfoStub = sinon.stub(SourceMapGenerator.rollupObject, 'getModuleInfo').returns(undefined);
122    const stub = sinon.stub(sourceMapGenerator.logger.getLoggerFromErrorCode(errInfo.code), 'printErrorAndExit');
123
124    try {
125      sourceMapGenerator.getPkgInfoByModuleId(moduleId);
126    } catch (e) {
127    }
128    expect(stub.calledWith(errInfo)).to.be.true;
129    getModuleInfoStub.restore();
130    stub.restore();
131    SourceMapGenerator.cleanSourceMapObject();
132  })
133
134  mocha.it('1-6-1: test GetModuleInfoFaild error of getPkgInfoByModuleId ' +
135    'without getHvigorConsoleLogger', function () {
136    this.rollup.build();
137    const errInfo: LogData = LogDataFactory.newInstance(
138      ErrorCode.ETS2BUNDLE_INTERNAL_GET_MODULE_INFO_FAILED,
139      ArkTSInternalErrorDescription,
140      'Failed to get ModuleInfo, moduleId: moduleId'
141    );
142    CommonLogger.destroyInstance();
143    const getHvigorConsoleLogger = this.rollup.share.getHvigorConsoleLogger;
144    this.rollup.share.getHvigorConsoleLogger = undefined;
145    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
146    let moduleId = "moduleId";
147    const getModuleInfoStub = sinon.stub(SourceMapGenerator.rollupObject, 'getModuleInfo').returns(undefined);
148    const stub = sinon.stub(sourceMapGenerator.logger, 'throwArkTsCompilerError');
149
150    try {
151      sourceMapGenerator.getPkgInfoByModuleId(moduleId);
152    } catch (e) {
153    }
154    expect(stub.calledWith(errInfo.toString())).to.be.true;
155    CommonLogger.destroyInstance();
156    this.rollup.share.getHvigorConsoleLogger = getHvigorConsoleLogger;
157    getModuleInfoStub.restore();
158    stub.restore();
159    SourceMapGenerator.cleanSourceMapObject();
160  })
161
162  mocha.it('1-7: test UnableToGetModuleInfoMeta error of getPkgInfoByModuleId', function () {
163    this.rollup.build();
164    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
165    let moduleId = "moduleId";
166    const getModuleInfoStub = sinon.stub(SourceMapGenerator.rollupObject, 'getModuleInfo').returns({'meta': undefined});
167    const stub = sinon.stub(sourceMapGenerator.logger, 'printErrorAndExit');
168
169    try {
170      sourceMapGenerator.getPkgInfoByModuleId(moduleId);
171    } catch (e) {
172    }
173    const errInfo: LogData = LogDataFactory.newInstance(
174      ErrorCode.ETS2BUNDLE_INTERNAL_UNABLE_TO_GET_MODULE_INFO_META,
175      ArkTSInternalErrorDescription,
176      "Failed to get ModuleInfo properties 'meta', moduleId: moduleId"
177    );
178    expect(stub.calledWith(errInfo)).to.be.true;
179    getModuleInfoStub.restore();
180    stub.restore();
181    SourceMapGenerator.cleanSourceMapObject();
182  })
183
184  mocha.it('1-8: test UnableToGetModuleInfoMetaPkgPath error of getPkgInfoByModuleId', function () {
185    this.rollup.build();
186    const errInfo: LogData = LogDataFactory.newInstance(
187      ErrorCode.ETS2BUNDLE_INTERNAL_UNABLE_TO_GET_MODULE_INFO_META_PKG_PATH,
188      ArkTSInternalErrorDescription,
189      "Failed to get ModuleInfo properties 'meta.pkgPath', moduleId: moduleId"
190    );
191    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
192    let moduleId = "moduleId";
193    const getModuleInfoStub = sinon.stub(SourceMapGenerator.rollupObject, 'getModuleInfo').returns({'meta': {'pkgPath': undefined}});
194    const stub = sinon.stub(sourceMapGenerator.logger.getLoggerFromErrorCode(errInfo.code), 'printErrorAndExit');
195
196    try {
197      sourceMapGenerator.getPkgInfoByModuleId(moduleId);
198    } catch (e) {
199    }
200    expect(stub.calledWith(errInfo)).to.be.true;
201    getModuleInfoStub.restore();
202    stub.restore();
203    SourceMapGenerator.cleanSourceMapObject();
204  })
205
206  mocha.it('1-9: test UnableToGetModuleInfoMetaPkgPath error of getPkgInfoByModuleId ' +
207    'without getHvigorConsoleLogger', function () {
208    this.rollup.build();
209    const errInfo: LogData = LogDataFactory.newInstance(
210      ErrorCode.ETS2BUNDLE_INTERNAL_UNABLE_TO_GET_MODULE_INFO_META_PKG_PATH,
211      ArkTSInternalErrorDescription,
212      "Failed to get ModuleInfo properties 'meta.pkgPath', moduleId: moduleId"
213    );
214    CommonLogger.destroyInstance();
215    const getHvigorConsoleLogger = this.rollup.share.getHvigorConsoleLogger;
216    this.rollup.share.getHvigorConsoleLogger = undefined;
217    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
218    let moduleId = "moduleId";
219    const getModuleInfoStub = sinon.stub(SourceMapGenerator.rollupObject, 'getModuleInfo').returns({'meta': {'pkgPath': undefined}});
220    const stub = sinon.stub(sourceMapGenerator.logger, 'throwArkTsCompilerError');
221
222    try {
223      sourceMapGenerator.getPkgInfoByModuleId(moduleId);
224    } catch (e) {
225    }
226    expect(stub.calledWith(errInfo.toString())).to.be.true;
227    CommonLogger.destroyInstance();
228    this.rollup.share.getHvigorConsoleLogger = getHvigorConsoleLogger;
229    getModuleInfoStub.restore();
230    stub.restore();
231    SourceMapGenerator.cleanSourceMapObject();
232  })
233
234  mocha.it('2-1: test genKey under build debug', function () {
235    this.rollup.build();
236    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
237    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
238    let genKey = sourceMapGenerator.genKey(moduleId);
239    let expectKey = prefix + ENTRYABILITY_JS_PATH_DEFAULT.substring(1);
240
241    expect(genKey === expectKey).to.be.true;
242    SourceMapGenerator.cleanSourceMapObject();
243  });
244
245  mocha.it('2-2: test genKey under build release', function () {
246    this.rollup.build(RELEASE);
247    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
248    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
249    let genKey = sourceMapGenerator.genKey(moduleId);
250    let expectKey = prefix + ENTRYABILITY_JS_PATH_DEFAULT.substring(1);
251
252    expect(genKey === expectKey).to.be.true;
253    SourceMapGenerator.cleanSourceMapObject();
254  });
255
256  mocha.it('2-3: test genKey under preview', function () {
257    this.rollup.preview();
258    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
259    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
260    let genKey = sourceMapGenerator.genKey(moduleId);
261    let expectKey = prefix + ENTRYABILITY_JS_PATH_DEFAULT.substring(1);
262
263    expect(genKey === expectKey).to.be.true;
264    SourceMapGenerator.cleanSourceMapObject();
265  });
266
267  mocha.it('2-4: test genKey under hotReload', function () {
268    this.rollup.hotReload();
269    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
270    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
271    let genKey = sourceMapGenerator.genKey(moduleId);
272    let expectKey = prefix + ENTRYABILITY_JS_PATH_DEFAULT.substring(1);
273
274    expect(genKey === expectKey).to.be.true;
275    SourceMapGenerator.cleanSourceMapObject();
276  });
277
278  mocha.it('2-5: test genKey with file name obfuscate', function () {
279    this.rollup.build();
280    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
281    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
282    let genKey = sourceMapGenerator.genKey(moduleId, true);
283    let expectKey = 'entry|entry|1.0.0|src/main/a/b.js';
284    expect(genKey === expectKey).to.be.true;
285    SourceMapGenerator.cleanSourceMapObject();
286  });
287
288  mocha.it('3-1: test updateSourceMap under build debug', function () {
289    this.rollup.build();
290    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
291    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
292    let sourceMapData = { version: '1.0.0' };
293    sourceMapGenerator.updateSourceMap(moduleId, sourceMapData);
294    let sourceMapDataGet = sourceMapGenerator.getSourceMap(moduleId);
295    expect(sourceMapData === sourceMapDataGet).to.be.true;
296    SourceMapGenerator.cleanSourceMapObject();
297  });
298
299  mocha.it('3-2: test updateSourceMap under build release', function () {
300    this.rollup.build(RELEASE);
301    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
302    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
303    let sourceMapData = { version: '1.0.0' };
304    sourceMapGenerator.updateSourceMap(moduleId, sourceMapData);
305    let sourceMapDataGet = sourceMapGenerator.getSourceMap(moduleId);
306    expect(sourceMapData === sourceMapDataGet).to.be.true;
307    SourceMapGenerator.cleanSourceMapObject();
308  });
309
310  mocha.it('3-3: test updateSourceMap under preview', function () {
311    this.rollup.preview();
312    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
313    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
314    let sourceMapData = { version: '1.0.0' };
315    sourceMapGenerator.updateSourceMap(moduleId, sourceMapData);
316    let sourceMapDataGet = sourceMapGenerator.getSourceMap(moduleId);
317    expect(sourceMapData === sourceMapDataGet).to.be.true;
318    SourceMapGenerator.cleanSourceMapObject();
319  });
320
321  mocha.it('3-4: test updateSourceMap under hotReload', function () {
322    this.rollup.hotReload();
323    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
324    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
325    let sourceMapData = { version: '1.0.0' };
326    sourceMapGenerator.updateSourceMap(moduleId, sourceMapData);
327    let sourceMapDataGet = sourceMapGenerator.getSourceMap(moduleId);
328    expect(sourceMapData === sourceMapDataGet).to.be.true;
329    SourceMapGenerator.cleanSourceMapObject();
330  });
331
332  mocha.it('4-1: test fillSourceMapPackageInfo under build debug', function () {
333    this.rollup.build();
334    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
335
336    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
337    let sourceMapData = {};
338    sourceMapGenerator.fillSourceMapPackageInfo(moduleId, sourceMapData);
339    expect(sourceMapData['entry-package-info'] && sourceMapData['entry-package-info'] === entryPkgInfo).to.be.true;
340    SourceMapGenerator.cleanSourceMapObject();
341  });
342
343  mocha.it('4-2: test fillSourceMapPackageInfo under build release', function () {
344    this.rollup.build(RELEASE);
345    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
346
347    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
348    let sourceMapData = {};
349    sourceMapGenerator.fillSourceMapPackageInfo(moduleId, sourceMapData);
350    expect(sourceMapData['entry-package-info'] && sourceMapData['entry-package-info'] === entryPkgInfo).to.be.true;
351    SourceMapGenerator.cleanSourceMapObject();
352  });
353
354  mocha.it('4-3: test fillSourceMapPackageInfo under preview', function () {
355    this.rollup.preview();
356    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
357
358    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
359    let sourceMapData = {};
360    sourceMapGenerator.fillSourceMapPackageInfo(moduleId, sourceMapData);
361    expect(sourceMapData['entry-package-info'] && sourceMapData['entry-package-info'] === entryPkgInfo).to.be.true;
362    SourceMapGenerator.cleanSourceMapObject();
363  });
364
365  mocha.it('4-4: test fillSourceMapPackageInfo under hotReload', function () {
366    this.rollup.hotReload();
367    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
368
369    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
370    let sourceMapData = {};
371    sourceMapGenerator.fillSourceMapPackageInfo(moduleId, sourceMapData);
372    expect(sourceMapData['entry-package-info'] && sourceMapData['entry-package-info'] === entryPkgInfo).to.be.true;
373    SourceMapGenerator.cleanSourceMapObject();
374  });
375
376  mocha.it('5-1: test genKey under build debug: arkProjectConfig.processTs is true', function () {
377    this.rollup.build();
378    this.rollup.share.arkProjectConfig.processTs = true;
379    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
380    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
381    compilingEtsOrTsFiles.push(moduleId);
382    hasTsNoCheckOrTsIgnoreFiles.push(moduleId);
383    let genKey = sourceMapGenerator.genKey(moduleId);
384    cleanUpFilesList();
385    let expectKey = prefix + ENTRYABILITY_JS_PATH_DEFAULT.substring(1);
386    expect(genKey === expectKey).to.be.true;
387    SourceMapGenerator.cleanSourceMapObject();
388  });
389
390  mocha.it('5-2: test genKey under build release: arkProjectConfig.processTs is true', function () {
391    this.rollup.build(RELEASE);
392    this.rollup.share.arkProjectConfig.processTs = true;
393    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
394    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
395    compilingEtsOrTsFiles.push(moduleId);
396    hasTsNoCheckOrTsIgnoreFiles.push(moduleId);
397    let genKey = sourceMapGenerator.genKey(moduleId);
398    cleanUpFilesList();
399    let expectKey = prefix + ENTRYABILITY_JS_PATH_DEFAULT.substring(1);
400    expect(genKey === expectKey).to.be.true;
401    SourceMapGenerator.cleanSourceMapObject();
402  });
403
404  mocha.it('5-3: test genKey under preview: arkProjectConfig.processTs is true', function () {
405    this.rollup.preview();
406    this.rollup.share.arkProjectConfig.processTs = true;
407    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
408    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
409    compilingEtsOrTsFiles.push(moduleId);
410    hasTsNoCheckOrTsIgnoreFiles.push(moduleId);
411    let genKey = sourceMapGenerator.genKey(moduleId);
412    cleanUpFilesList();
413    let expectKey = prefix + ENTRYABILITY_JS_PATH_DEFAULT.substring(1);
414    expect(genKey === expectKey).to.be.true;
415    SourceMapGenerator.cleanSourceMapObject();
416  });
417
418  mocha.it('5-4: test genKey under hotReload: arkProjectConfig.processTs is true', function () {
419    this.rollup.hotReload();
420    this.rollup.share.arkProjectConfig.processTs = true;
421    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
422    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
423    compilingEtsOrTsFiles.push(moduleId);
424    hasTsNoCheckOrTsIgnoreFiles.push(moduleId);
425    let genKey = sourceMapGenerator.genKey(moduleId);
426    cleanUpFilesList();
427    let expectKey = prefix + ENTRYABILITY_JS_PATH_DEFAULT.substring(1);
428    expect(genKey === expectKey).to.be.true;
429    SourceMapGenerator.cleanSourceMapObject();
430  });
431
432  mocha.it('6-1: test updateCachedSourceMaps under build debug: arkProjectConfig.processTs is true', function () {
433    this.rollup.build();
434    this.rollup.share.arkProjectConfig.processTs = true;
435    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, INDEX_ETS_PATH_DEFAULT);
436    compilingEtsOrTsFiles.push(moduleId);
437    hasTsNoCheckOrTsIgnoreFiles.push(moduleId);
438    const indexCachePath = this.rollup.share.projectConfig.projectRootPath + '/' + INDEX_JS_CACHE_PATH;
439    if (fs.existsSync(indexCachePath)) {
440      fs.rmSync(indexCachePath);
441    }
442    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
443    sourceMapGenerator.isNewSourceMap = false;
444    const rootPath = this.rollup.share.projectConfig.projectRootPath + '/cache/';
445    const sourceMapEdit = JSON.parse(fs.readFileSync(rootPath + 'source_map_edit.json').toString());
446    const sourceMapExpect = JSON.parse(fs.readFileSync(rootPath + 'source_map_expect.json').toString());
447    sourceMapGenerator.cacheSourceMapPath = rootPath + 'source_map_cache.json';
448    sourceMapGenerator.sourceMaps = sourceMapEdit;
449    const sourceMapResult = sourceMapGenerator.updateCachedSourceMaps();
450    expect(Object.keys(sourceMapResult).length == Object.keys(sourceMapExpect).length).to.be.true;
451    Object.keys(sourceMapResult).forEach(key => {
452      expect(sourceMapExpect).to.include.keys(key);
453    });
454    SourceMapGenerator.cleanSourceMapObject();
455  });
456
457  mocha.it('6-2: test updateCachedSourceMaps under build release: arkProjectConfig.processTs is true', function () {
458    this.rollup.build(RELEASE);
459    this.rollup.share.arkProjectConfig.processTs = true;
460    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, INDEX_ETS_PATH_DEFAULT);
461    compilingEtsOrTsFiles.push(moduleId);
462    hasTsNoCheckOrTsIgnoreFiles.push(moduleId);
463    const indexCachePath = this.rollup.share.projectConfig.projectRootPath + '/' + INDEX_JS_CACHE_PATH;
464    if (fs.existsSync(indexCachePath)) {
465      fs.rmSync(indexCachePath);
466    }
467    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
468    sourceMapGenerator.isNewSourceMap = false;
469    const rootPath = this.rollup.share.projectConfig.projectRootPath + '/cache/';
470    const sourceMapEdit = JSON.parse(fs.readFileSync(rootPath + 'source_map_edit.json').toString());
471    const sourceMapExpect = JSON.parse(fs.readFileSync(rootPath + 'source_map_expect.json').toString());
472    sourceMapGenerator.cacheSourceMapPath = rootPath + 'source_map_cache.json';
473    sourceMapGenerator.sourceMaps = sourceMapEdit;
474    const sourceMapResult = sourceMapGenerator.updateCachedSourceMaps();
475    expect(Object.keys(sourceMapResult).length == Object.keys(sourceMapExpect).length).to.be.true;
476    Object.keys(sourceMapResult).forEach(key => {
477      expect(sourceMapExpect).to.include.keys(key);
478    });
479    SourceMapGenerator.cleanSourceMapObject();
480  });
481
482  mocha.it('6-3: test updateCachedSourceMaps under preview: arkProjectConfig.processTs is true', function () {
483    this.rollup.preview();
484    this.rollup.share.arkProjectConfig.processTs = true;
485    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, INDEX_ETS_PATH_DEFAULT);
486    compilingEtsOrTsFiles.push(moduleId);
487    hasTsNoCheckOrTsIgnoreFiles.push(moduleId);
488    const indexCachePath = this.rollup.share.projectConfig.projectRootPath + '/' + INDEX_JS_CACHE_PATH;
489    if (fs.existsSync(indexCachePath)) {
490      fs.rmSync(indexCachePath);
491    }
492    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
493    sourceMapGenerator.isNewSourceMap = false;
494    const rootPath = this.rollup.share.projectConfig.projectRootPath + '/cache/';
495    const sourceMapEdit = JSON.parse(fs.readFileSync(rootPath + 'source_map_edit.json').toString());
496    const sourceMapExpect = JSON.parse(fs.readFileSync(rootPath + 'source_map_expect_preview.json').toString());
497    sourceMapGenerator.cacheSourceMapPath = rootPath + 'source_map_cache_preview.json';
498    sourceMapGenerator.sourceMaps = sourceMapEdit;
499    const sourceMapResult = sourceMapGenerator.updateCachedSourceMaps();
500    expect(Object.keys(sourceMapResult).length == Object.keys(sourceMapExpect).length).to.be.true;
501    Object.keys(sourceMapResult).forEach(key => {
502      expect(sourceMapExpect).to.include.keys(key);
503    });
504    SourceMapGenerator.cleanSourceMapObject();
505  });
506
507  mocha.it('6-4: test updateCachedSourceMaps under hotReload: arkProjectConfig.processTs is true', function () {
508    this.rollup.hotReload();
509    this.rollup.share.arkProjectConfig.processTs = true;
510    let moduleId = path.join(this.rollup.share.projectConfig.modulePath, INDEX_ETS_PATH_DEFAULT);
511    compilingEtsOrTsFiles.push(moduleId);
512    hasTsNoCheckOrTsIgnoreFiles.push(moduleId);
513    const indexCachePath = this.rollup.share.projectConfig.projectRootPath + '/' + INDEX_JS_CACHE_PATH;
514    if (fs.existsSync(indexCachePath)) {
515      fs.rmSync(indexCachePath);
516    }
517    const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
518    sourceMapGenerator.isNewSourceMap = false;
519    const rootPath = this.rollup.share.projectConfig.projectRootPath + '/cache/';
520    const sourceMapEdit = JSON.parse(fs.readFileSync(rootPath + 'source_map_edit.json').toString());
521    const sourceMapExpect = JSON.parse(fs.readFileSync(rootPath + 'source_map_expect.json').toString());
522    sourceMapGenerator.cacheSourceMapPath = rootPath + 'source_map_cache.json';
523    sourceMapGenerator.sourceMaps = sourceMapEdit;
524    const sourceMapResult = sourceMapGenerator.updateCachedSourceMaps();
525    expect(Object.keys(sourceMapResult).length == Object.keys(sourceMapExpect).length).to.be.true;
526    Object.keys(sourceMapResult).forEach(key => {
527      expect(sourceMapExpect).to.include.keys(key);
528    });
529    SourceMapGenerator.cleanSourceMapObject();
530  });
531
532});