[ci] yarn format

This commit is contained in:
matthewp 2021-06-07 18:26:17 +00:00 committed by GitHub Actions
parent b1364afbae
commit cb3ff36105
3 changed files with 17 additions and 20 deletions

View file

@ -4,28 +4,25 @@ function verboseLogging() {
return process.argv.includes('--verbose'); return process.argv.includes('--verbose');
} }
const onceMessages = [ const onceMessages = ['Ready!', 'watching for file changes'].map((str) => new RegExp(`\\[snowpack\\](.*?)${str}`));
'Ready!',
'watching for file changes'
].map(str => new RegExp(`\\[snowpack\\](.*?)${str}`));
export function configureSnowpackLogger(logger: typeof snowpackLogger) { export function configureSnowpackLogger(logger: typeof snowpackLogger) {
const messageCache = new Set<string>(); const messageCache = new Set<string>();
if(verboseLogging()) { if (verboseLogging()) {
logger.level = 'debug'; logger.level = 'debug';
} }
logger.on('info', message => { logger.on('info', (message) => {
// Cache messages that should only be shown once. // Cache messages that should only be shown once.
// This is due to having 2 snowpack instances. Once that is removed we can // This is due to having 2 snowpack instances. Once that is removed we can
// get rid of this workaround. // get rid of this workaround.
if(messageCache.has(message)) { if (messageCache.has(message)) {
return; return;
} }
const shouldBeCached = onceMessages.some(exp => exp.test(message)); const shouldBeCached = onceMessages.some((exp) => exp.test(message));
if(shouldBeCached) { if (shouldBeCached) {
messageCache.add(message); messageCache.add(message);
} }

View file

@ -4,7 +4,7 @@ import { clearCache, runDevServer } from './helpers.js';
import isWindows from 'is-windows'; import isWindows from 'is-windows';
// For some reason Windows isn't getting anything from stdout in this test, not sure why. // For some reason Windows isn't getting anything from stdout in this test, not sure why.
if(!isWindows()) { if (!isWindows()) {
const SnowpackLogging = suite('snowpack logging'); const SnowpackLogging = suite('snowpack logging');
const MAX_TEST_TIME = 10000; // max time this test suite may take const MAX_TEST_TIME = 10000; // max time this test suite may take
@ -12,7 +12,7 @@ if(!isWindows()) {
const exp = new RegExp(message, 'g'); const exp = new RegExp(message, 'g');
let count = 0; let count = 0;
let res; let res;
while(res = exp.exec(stdout)) { while ((res = exp.exec(stdout))) {
count++; count++;
} }
return count; return count;
@ -21,7 +21,7 @@ if(!isWindows()) {
const root = new URL('./fixtures/astro/basic/', import.meta.url); const root = new URL('./fixtures/astro/basic/', import.meta.url);
const timers = {}; const timers = {};
let runError = null; let runError = null;
SnowpackLogging.before(async context => { SnowpackLogging.before(async (context) => {
await clearCache(); await clearCache();
let importantMessages = 0; let importantMessages = 0;
@ -35,20 +35,20 @@ if(!isWindows()) {
if (/Server started/.test(chunk)) { if (/Server started/.test(chunk)) {
importantMessages++; importantMessages++;
} }
if(/Ready/.test(chunk)) { if (/Ready/.test(chunk)) {
importantMessages++; importantMessages++;
} }
if(/watching for file changes/.test(chunk)) { if (/watching for file changes/.test(chunk)) {
importantMessages++; importantMessages++;
} }
if(importantMessages === 3) { if (importantMessages === 3) {
break; break;
} }
} }
context.stdout = stdout; context.stdout = stdout;
process.kill(); process.kill();
} catch(err) { } catch (err) {
console.error(err); console.error(err);
runError = runError; runError = runError;
} }
@ -70,7 +70,7 @@ if(!isWindows()) {
SnowpackLogging('Logs [waiting for file changes] once', ({ stdout }) => { SnowpackLogging('Logs [waiting for file changes] once', ({ stdout }) => {
assert.equal(numberOfEntries(stdout, 'watching for file changes'), 1); assert.equal(numberOfEntries(stdout, 'watching for file changes'), 1);
}) });
SnowpackLogging.after.each(({ __test__ }) => { SnowpackLogging.after.each(({ __test__ }) => {
clearTimeout(timers[__test__]); clearTimeout(timers[__test__]);