test: use new uuid for each ServiceWorker test (#27444)

This commit is contained in:
Cheng Zhao 2021-01-23 10:37:51 +09:00 committed by GitHub
parent 70190ec2b1
commit 9baca911a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,26 +1,27 @@
import * as fs from 'fs'; import * as fs from 'fs';
import * as http from 'http'; import * as http from 'http';
import * as path from 'path'; import * as path from 'path';
import { session, BrowserWindow } from 'electron/main'; import { session, webContents, WebContents } from 'electron/main';
import { expect } from 'chai'; import { expect } from 'chai';
import { v4 } from 'uuid'; import { v4 } from 'uuid';
import { AddressInfo } from 'net'; import { AddressInfo } from 'net';
import { closeWindow } from './window-helpers';
import { emittedOnce, emittedNTimes } from './events-helpers'; import { emittedOnce, emittedNTimes } from './events-helpers';
import { ifdescribe } from './spec-helpers';
const partition = 'service-workers-spec'; const partition = 'service-workers-spec';
const uuid = v4();
describe('session.serviceWorkers', () => { describe('session.serviceWorkers', () => {
let ses: Electron.Session; let ses: Electron.Session;
let server: http.Server; let server: http.Server;
let baseUrl: string; let baseUrl: string;
let w: BrowserWindow; let w: WebContents = null as unknown as WebContents;
before(async () => { before(async () => {
ses = session.fromPartition(partition); ses = session.fromPartition(partition);
await ses.clearStorageData(); await ses.clearStorageData();
});
beforeEach(async () => {
const uuid = v4();
server = http.createServer((req, res) => { server = http.createServer((req, res) => {
// /{uuid}/{file} // /{uuid}/{file}
@ -37,20 +38,14 @@ describe('session.serviceWorkers', () => {
resolve(); resolve();
}); });
}); });
});
beforeEach(() => { w = (webContents as any).create({ session: ses });
w = new BrowserWindow({ show: false, webPreferences: { session: ses } });
}); });
afterEach(async () => { afterEach(async () => {
await ses.clearStorageData(); (w as any).destroy();
await closeWindow(w);
w = null as any;
});
after(async () => {
server.close(); server.close();
await ses.clearStorageData();
}); });
describe('getAllRunning()', () => { describe('getAllRunning()', () => {
@ -66,8 +61,7 @@ describe('session.serviceWorkers', () => {
}); });
}); });
// TODO (jkleinsc) - reenable this test once https://github.com/electron/electron/issues/26043 is resolved describe('getFromVersionID()', () => {
ifdescribe(!process.arch.includes('arm'))('getFromVersionID()', () => {
it('should report the correct script url and scope', async () => { it('should report the correct script url and scope', async () => {
const eventInfo = await emittedOnce(ses.serviceWorkers, 'console-message', () => w.loadURL(`${baseUrl}/index.html`)); const eventInfo = await emittedOnce(ses.serviceWorkers, 'console-message', () => w.loadURL(`${baseUrl}/index.html`));
const details: Electron.MessageDetails = eventInfo[1]; const details: Electron.MessageDetails = eventInfo[1];