mirror of
				https://github.com/microsoft/playwright.git
				synced 2025-06-26 21:40:17 +00:00 
			
		
		
		
	chore: audit code for new Promise(async) (#8601)
This commit is contained in:
		
							parent
							
								
									1c169289b2
								
							
						
					
					
						commit
						26e7c2825b
					
				@ -928,14 +928,7 @@ export class Frame extends SdkObject {
 | 
			
		||||
    let result: dom.ElementHandle;
 | 
			
		||||
    let error: Error | undefined;
 | 
			
		||||
    let cspMessage: ConsoleMessage | undefined;
 | 
			
		||||
    const actionPromise = new Promise<void>(async resolve => {
 | 
			
		||||
      try {
 | 
			
		||||
        result = await func();
 | 
			
		||||
      } catch (e) {
 | 
			
		||||
        error = e;
 | 
			
		||||
      }
 | 
			
		||||
      resolve();
 | 
			
		||||
    });
 | 
			
		||||
    const actionPromise = func().then(r => result = r).catch(e => error = e);
 | 
			
		||||
    const errorPromise = new Promise<void>(resolve => {
 | 
			
		||||
      listeners.push(eventsHelper.addEventListener(this._page, Page.Events.Console, (message: ConsoleMessage) => {
 | 
			
		||||
        if (message.type() === 'error' && message.text().includes('Content Security Policy')) {
 | 
			
		||||
 | 
			
		||||
@ -190,19 +190,18 @@ export class Tracing implements InstrumentationListener, SnapshotterDelegate, Ha
 | 
			
		||||
      const state = this._recording!;
 | 
			
		||||
      const zipFile = new yazl.ZipFile();
 | 
			
		||||
      const failedPromise = new Promise<Artifact>((_, reject) => (zipFile as any as EventEmitter).on('error', reject));
 | 
			
		||||
      const succeededPromise = new Promise<Artifact>(async fulfill => {
 | 
			
		||||
      const succeededPromise = new Promise<Artifact>(fulfill => {
 | 
			
		||||
        zipFile.addFile(state.traceFile, 'trace.trace');
 | 
			
		||||
        zipFile.addFile(state.networkFile, 'trace.network');
 | 
			
		||||
        const zipFileName = state.traceFile + '.zip';
 | 
			
		||||
        for (const sha1 of state.sha1s)
 | 
			
		||||
          zipFile.addFile(path.join(this._resourcesDir, sha1), path.join('resources', sha1));
 | 
			
		||||
        zipFile.end();
 | 
			
		||||
        await new Promise(f => {
 | 
			
		||||
          zipFile.outputStream.pipe(fs.createWriteStream(zipFileName)).on('close', f);
 | 
			
		||||
        zipFile.outputStream.pipe(fs.createWriteStream(zipFileName)).on('close', () => {
 | 
			
		||||
          const artifact = new Artifact(this._context, zipFileName);
 | 
			
		||||
          artifact.reportFinished();
 | 
			
		||||
          fulfill(artifact);
 | 
			
		||||
        });
 | 
			
		||||
        const artifact = new Artifact(this._context, zipFileName);
 | 
			
		||||
        artifact.reportFinished();
 | 
			
		||||
        fulfill(artifact);
 | 
			
		||||
      });
 | 
			
		||||
      return Promise.race([failedPromise, succeededPromise]);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
@ -38,10 +38,10 @@ export async function stopProfiling(workerIndex: number | undefined) {
 | 
			
		||||
  if (!profileDir)
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
  await new Promise<void>(f => session.post('Profiler.stop', async (err, { profile }) => {
 | 
			
		||||
  await new Promise<void>(f => session.post('Profiler.stop', (err, { profile }) => {
 | 
			
		||||
    if (!err) {
 | 
			
		||||
      await fs.promises.mkdir(profileDir, { recursive: true });
 | 
			
		||||
      await fs.promises.writeFile(path.join(profileDir, workerIndex === undefined ? 'runner.json' : 'worker' + workerIndex + '.json'), JSON.stringify(profile));
 | 
			
		||||
      fs.mkdirSync(profileDir, { recursive: true });
 | 
			
		||||
      fs.writeFileSync(path.join(profileDir, workerIndex === undefined ? 'runner.json' : 'worker' + workerIndex + '.json'), JSON.stringify(profile));
 | 
			
		||||
    }
 | 
			
		||||
    f();
 | 
			
		||||
  }));
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user