test: convert a few more specs to async/await (#40313)

This commit is contained in:
Milan Burda 2023-11-17 10:44:03 +01:00 committed by GitHub
parent 471449d9f6
commit 67894f1493
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 48 additions and 61 deletions

View file

@ -3,7 +3,7 @@ import { app, session, BrowserWindow, ipcMain, WebContents, Extension, Session }
import { closeAllWindows, closeWindow } from './lib/window-helpers';
import * as http from 'node:http';
import * as path from 'node:path';
import * as fs from 'node:fs';
import * as fs from 'node:fs/promises';
import * as WebSocket from 'ws';
import { emittedNTimes, emittedUntil } from './lib/events-helpers';
import { ifit, listen } from './lib/spec-helpers';
@ -200,7 +200,7 @@ describe('chrome extensions', () => {
it('serializes a loaded extension', async () => {
const extensionPath = path.join(fixtures, 'extensions', 'red-bg');
const manifest = JSON.parse(fs.readFileSync(path.join(extensionPath, 'manifest.json'), 'utf-8'));
const manifest = JSON.parse(await fs.readFile(path.join(extensionPath, 'manifest.json'), 'utf-8'));
const customSession = session.fromPartition(`persist:${uuid.v4()}`);
const extension = await customSession.loadExtension(extensionPath);
expect(extension.id).to.be.a('string');
@ -684,16 +684,15 @@ describe('chrome extensions', () => {
let server: http.Server;
let port: number;
before(async () => {
server = http.createServer((_, res) => {
fs.readFile(contentPath, (error, content) => {
if (error) {
res.writeHead(500);
res.end(`Failed to load ${contentPath} : ${error.code}`);
} else {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(content, 'utf-8');
}
});
server = http.createServer(async (_, res) => {
try {
const content = await fs.readFile(contentPath, 'utf-8');
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(content, 'utf-8');
} catch (error) {
res.writeHead(500);
res.end(`Failed to load ${contentPath} : ${(error as NodeJS.ErrnoException).code}`);
}
});
({ port, url } = await listen(server));