test: drop now-empty remote runner (#35343)
* test: drop the now-empty remote runner from CI * move fixtures to spec-main * remove remote runner * fix stuff * remove global-paths hack * move ts-smoke to spec/ * fix test after merge * rename spec-main to spec * no need to ignore spec/node_modules twice * simplify spec-runner a little * no need to hash pj/yl twice * undo lint change to verify-mksnapshot.py * excessive .. * update electron_woa_testing.yml * don't search for test-results-remote.xml it is never produced now
This commit is contained in:
parent
e87c4015fe
commit
db7c92fd57
327 changed files with 950 additions and 1707 deletions
95
spec/api-service-workers-spec.ts
Normal file
95
spec/api-service-workers-spec.ts
Normal file
|
@ -0,0 +1,95 @@
|
|||
import * as fs from 'fs';
|
||||
import * as http from 'http';
|
||||
import * as path from 'path';
|
||||
import { session, webContents, WebContents } from 'electron/main';
|
||||
import { expect } from 'chai';
|
||||
import { v4 } from 'uuid';
|
||||
import { AddressInfo } from 'net';
|
||||
import { emittedOnce, emittedNTimes } from './events-helpers';
|
||||
|
||||
const partition = 'service-workers-spec';
|
||||
|
||||
describe('session.serviceWorkers', () => {
|
||||
let ses: Electron.Session;
|
||||
let server: http.Server;
|
||||
let baseUrl: string;
|
||||
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}
|
||||
const file = req.url!.split('/')[2]!;
|
||||
|
||||
if (file.endsWith('.js')) {
|
||||
res.setHeader('Content-Type', 'application/javascript');
|
||||
}
|
||||
res.end(fs.readFileSync(path.resolve(__dirname, 'fixtures', 'api', 'service-workers', file)));
|
||||
});
|
||||
await new Promise<void>(resolve => {
|
||||
server.listen(0, '127.0.0.1', () => {
|
||||
baseUrl = `http://localhost:${(server.address() as AddressInfo).port}/${uuid}`;
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
w = (webContents as any).create({ session: ses });
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
(w as any).destroy();
|
||||
server.close();
|
||||
await ses.clearStorageData();
|
||||
});
|
||||
|
||||
describe('getAllRunning()', () => {
|
||||
it('should initially report none are running', () => {
|
||||
expect(ses.serviceWorkers.getAllRunning()).to.deep.equal({});
|
||||
});
|
||||
|
||||
it('should report one as running once you load a page with a service worker', async () => {
|
||||
await emittedOnce(ses.serviceWorkers, 'console-message', () => w.loadURL(`${baseUrl}/index.html`));
|
||||
const workers = ses.serviceWorkers.getAllRunning();
|
||||
const ids = Object.keys(workers) as any[] as number[];
|
||||
expect(ids).to.have.lengthOf(1, 'should have one worker running');
|
||||
});
|
||||
});
|
||||
|
||||
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];
|
||||
const worker = ses.serviceWorkers.getFromVersionID(details.versionId);
|
||||
expect(worker).to.not.equal(null);
|
||||
expect(worker).to.have.property('scope', baseUrl + '/');
|
||||
expect(worker).to.have.property('scriptUrl', baseUrl + '/sw.js');
|
||||
});
|
||||
});
|
||||
|
||||
describe('console-message event', () => {
|
||||
it('should correctly keep the source, message and level', async () => {
|
||||
const messages: Record<string, Electron.MessageDetails> = {};
|
||||
const events = await emittedNTimes(ses.serviceWorkers, 'console-message', 4, () => w.loadURL(`${baseUrl}/logs.html`));
|
||||
for (const event of events) {
|
||||
messages[event[1].message] = event[1];
|
||||
|
||||
expect(event[1]).to.have.property('source', 'console-api');
|
||||
}
|
||||
|
||||
expect(messages).to.have.property('log log');
|
||||
expect(messages).to.have.property('info log');
|
||||
expect(messages).to.have.property('warn log');
|
||||
expect(messages).to.have.property('error log');
|
||||
expect(messages['log log']).to.have.property('level', 1);
|
||||
expect(messages['info log']).to.have.property('level', 1);
|
||||
expect(messages['warn log']).to.have.property('level', 2);
|
||||
expect(messages['error log']).to.have.property('level', 3);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue