From 9baca911a1d00a37a4b04415746b2b4e5525ba08 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 23 Jan 2021 10:37:51 +0900 Subject: [PATCH] test: use new uuid for each ServiceWorker test (#27444) --- spec-main/api-service-workers-spec.ts | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/spec-main/api-service-workers-spec.ts b/spec-main/api-service-workers-spec.ts index 3411288c3954..5f7f81f9182f 100644 --- a/spec-main/api-service-workers-spec.ts +++ b/spec-main/api-service-workers-spec.ts @@ -1,26 +1,27 @@ import * as fs from 'fs'; import * as http from 'http'; import * as path from 'path'; -import { session, BrowserWindow } from 'electron/main'; +import { session, webContents, WebContents } from 'electron/main'; import { expect } from 'chai'; import { v4 } from 'uuid'; import { AddressInfo } from 'net'; -import { closeWindow } from './window-helpers'; import { emittedOnce, emittedNTimes } from './events-helpers'; -import { ifdescribe } from './spec-helpers'; const partition = 'service-workers-spec'; -const uuid = v4(); describe('session.serviceWorkers', () => { let ses: Electron.Session; let server: http.Server; let baseUrl: string; - let w: BrowserWindow; + let w: WebContents = null as unknown as WebContents; before(async () => { ses = session.fromPartition(partition); await ses.clearStorageData(); + }); + + beforeEach(async () => { + const uuid = v4(); server = http.createServer((req, res) => { // /{uuid}/{file} @@ -37,20 +38,14 @@ describe('session.serviceWorkers', () => { resolve(); }); }); - }); - beforeEach(() => { - w = new BrowserWindow({ show: false, webPreferences: { session: ses } }); + w = (webContents as any).create({ session: ses }); }); afterEach(async () => { - await ses.clearStorageData(); - await closeWindow(w); - w = null as any; - }); - - after(async () => { + (w as any).destroy(); server.close(); + await ses.clearStorageData(); }); describe('getAllRunning()', () => { @@ -66,8 +61,7 @@ describe('session.serviceWorkers', () => { }); }); - // TODO (jkleinsc) - reenable this test once https://github.com/electron/electron/issues/26043 is resolved - ifdescribe(!process.arch.includes('arm'))('getFromVersionID()', () => { + describe('getFromVersionID()', () => { it('should report the correct script url and scope', async () => { const eventInfo = await emittedOnce(ses.serviceWorkers, 'console-message', () => w.loadURL(`${baseUrl}/index.html`)); const details: Electron.MessageDetails = eventInfo[1];