Skip to content

Commit 3d68fab

Browse files
Move to Tap (#88)
* Use tap instead of ava * Split work for large compression tests * split successful tests based on project or config * Pushed Changes from Github Actions Bot
1 parent c1199ab commit 3d68fab

14 files changed

+199
-160
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ test/output/
33
node_modules/
44
.vscode/
55
.DS_Store
6+
.nyc_output
7+
coverage
68
yarn-error.log
79
yarn.lock
810
package-lock.json

package.json

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@
2525
"build-tests": "tsc -p test/tsconfig.json",
2626
"postbuild-tests": "tsc-esm -p test/tsconfig.json",
2727
"pretest": "yarn npm-run-all build build-tests",
28-
"test": "ava -v --timeout=2m",
28+
"test": "NODE_DISABLE_COLORS=1 tap --no-coverage --no-esm --node-arg=--experimental-modules test/output/**/*.test.mjs",
2929
"build": "rollup -c; chmod a+x dist/filesize",
3030
"try": "./dist/filesize",
3131
"release": "np --no-2fa",
3232
"prepublishOnly": "yarn npm-run-all clean build"
3333
},
3434
"dependencies": {
3535
"@kristoferbaxter/async": "1.0.0",
36+
"@kristoferbaxter/kleur": "4.0.1",
3637
"bytes": "3.1.0",
3738
"fast-glob": "3.2.2",
38-
"kleur": "3.0.3",
3939
"mri": "1.1.5"
4040
},
4141
"devDependencies": {
@@ -46,12 +46,13 @@
4646
"@types/bytes": "3.1.0",
4747
"@types/mri": "1.1.0",
4848
"@types/node": "13.13.4",
49-
"ava": "3.8.1",
49+
"@types/tap": "14.10.0",
5050
"np": "https://github.com/pixelastic/np/tarball/c3ab2e3b053c7da0ce40a572ca1616273ac080f8",
5151
"npm-run-all": "4.1.5",
5252
"prettier": "2.0.5",
5353
"rimraf": "3.0.2",
5454
"rollup": "2.7.3",
55+
"tap": "14.10.7",
5556
"tslib": "1.11.1",
5657
"typescript": "3.8.3",
5758
"typescript-esm": "1.0.1"
@@ -78,11 +79,6 @@
7879
"gzip": "10 kB"
7980
}
8081
},
81-
"ava": {
82-
"files": [
83-
"test/output/**/*.test.mjs"
84-
]
85-
},
8682
"publishConfig": {
8783
"access": "public"
8884
},

src/log/cli-report.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
const kleur = require('kleur');
17+
import kleur from '@kristoferbaxter/kleur';
1818
import { Report } from './report';
1919
import { Context, brotliSize, gzipSize, noneSize } from '../validation/Condition';
2020
import { maxFormatDisplay, formats } from './helpers/format';
@@ -23,12 +23,6 @@ import { write } from './helpers/output';
2323
import { prettyBytes } from './helpers/bytes';
2424
import { ICONS } from './helpers/icons';
2525

26-
// Disable output colors for test runs.
27-
kleur.enabled = !('AVA_PATH' in process.env);
28-
// Aliases to colors used.
29-
// @ts-ignore
30-
const { red, grey, yellow, green, bold, dim } = kleur;
31-
3226
export class CLIReport extends Report {
3327
protected maxPathDisplay: number;
3428
protected maxFormatDisplay: number;
@@ -45,7 +39,7 @@ export class CLIReport extends Report {
4539
}
4640

4741
private start(): void {
48-
write(bold('\n Filesizes\n'));
42+
write(kleur.bold('\n Filesizes\n'));
4943
write(`${''.padEnd(this.maxPathDisplay + 5)} ${formats(this.maxFormatDisplay)}\n`);
5044
}
5145

@@ -69,32 +63,32 @@ export class CLIReport extends Report {
6963

7064
if (size === undefined || size === null) {
7165
// Will not be calculated.
72-
this.currentLine += dim().grey('–'.padEnd(this.maxFormatDisplay));
66+
this.currentLine += kleur.dim().grey('–'.padEnd(this.maxFormatDisplay));
7367
return status;
7468
}
7569

7670
const outputBytes = prettyBytes(size);
7771
if (maxSize === undefined) {
78-
this.currentLine += dim().grey(outputBytes.padEnd(this.maxFormatDisplay));
72+
this.currentLine += kleur.dim().grey(outputBytes.padEnd(this.maxFormatDisplay));
7973
return status;
8074
}
8175
if (size < maxSize) {
8276
if (1 - size / maxSize < 0.05) {
8377
this.warning++;
8478
status.warning++;
85-
this.currentLine += yellow(outputBytes.padEnd(this.maxFormatDisplay));
79+
this.currentLine += kleur.yellow(outputBytes.padEnd(this.maxFormatDisplay));
8680
return status;
8781
}
8882

8983
this.success++;
9084
status.success++;
91-
this.currentLine += dim().green(outputBytes.padEnd(this.maxFormatDisplay));
85+
this.currentLine += kleur.dim().green(outputBytes.padEnd(this.maxFormatDisplay));
9286
return status;
9387
}
9488

9589
this.failure++;
9690
status.failure++;
97-
this.currentLine += red(outputBytes.padEnd(this.maxFormatDisplay));
91+
this.currentLine += kleur.red(outputBytes.padEnd(this.maxFormatDisplay));
9892
return status;
9993
}
10094

@@ -105,18 +99,18 @@ export class CLIReport extends Report {
10599
if (success > 0 || failure > 0 || warning > 0) {
106100
write(
107101
'\n ' +
108-
green(success + ` ${success === 1 ? 'check' : 'checks'} passed`) +
102+
kleur.green(success + ` ${success === 1 ? 'check' : 'checks'} passed`) +
109103
(failure === 0 ? ` ${ICONS['tada']}` : ''),
110104
);
111105
if (warning > 0) {
112106
write(
113107
'\n ' +
114-
yellow(warning + ` ${warning === 1 ? 'check' : 'checks'} warned`) +
115-
grey(' (within 5% of allowed size)'),
108+
kleur.yellow(warning + ` ${warning === 1 ? 'check' : 'checks'} warned`) +
109+
kleur.grey(' (within 5% of allowed size)'),
116110
);
117111
}
118112
if (failure > 0) {
119-
write('\n ' + red(failure + ` ${failure === 1 ? 'check' : 'checks'} failed`));
113+
write('\n ' + kleur.red(failure + ` ${failure === 1 ? 'check' : 'checks'} failed`));
120114
}
121115
write('\n\n');
122116
}

src/log/helpers/error.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,14 @@
1515
*/
1616

1717
import { write } from './output';
18-
import kleur from 'kleur';
19-
20-
// Disable output colors for test runs.
21-
kleur.enabled = !('AVA_PATH' in process.env);
22-
// Aliases to colors used.
23-
// @ts-ignore
24-
const { red } = kleur;
18+
import kleur from '@kristoferbaxter/kleur';
2519

2620
/**
2721
* Format output as an error message.
2822
* @param output
2923
*/
3024
export function MakeError(output: string): string {
31-
return `${red('error')} ${output}`;
25+
return `${kleur.red('error')} ${output}`;
3226
}
3327

3428
/**

src/log/no-tty-report.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
const kleur = require('kleur');
17+
import kleur from '@kristoferbaxter/kleur';
1818
import { Context, OrderedCompressionValues, SizeMap } from '../validation/Condition';
1919
import { write } from './helpers/output';
2020
import { ICONS } from './helpers/icons';
2121
import { CLIReport } from './cli-report';
2222

23-
// Disable output colors for test runs.
24-
kleur.enabled = !('AVA_PATH' in process.env);
25-
// Aliases to colors used.
26-
// @ts-ignore
27-
const { red, grey, yellow, green, bold, dim } = kleur;
28-
2923
export class NoTTYReport extends CLIReport {
3024
protected maxPathDisplay: number;
3125
protected maxFormatDisplay: number;
@@ -50,9 +44,9 @@ export class NoTTYReport extends CLIReport {
5044
}
5145

5246
if (failure > 0) {
53-
this.currentLine = ` ${red(ICONS['cross'])}${this.currentLine}`;
47+
this.currentLine = ` ${kleur.red(ICONS['cross'])}${this.currentLine}`;
5448
} else {
55-
this.currentLine = ` ${dim().green(ICONS['tick'])}${this.currentLine}`;
49+
this.currentLine = ` ${kleur.dim().green(ICONS['tick'])}${this.currentLine}`;
5650
}
5751

5852
write(this.currentLine + '\n');

src/log/tty-report.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
const kleur = require('kleur');
17+
import kleur from '@kristoferbaxter/kleur';
1818
import { Context, OrderedCompressionValues } from '../validation/Condition';
1919
import { write, erase } from './helpers/output';
2020
import { ICONS } from './helpers/icons';
2121
import { CLIReport } from './cli-report';
2222

23-
// Disable output colors for test runs.
24-
kleur.enabled = !('AVA_PATH' in process.env);
25-
// Aliases to colors used.
26-
// @ts-ignore
27-
const { red, grey, yellow, green, bold, dim } = kleur;
28-
2923
export class TTYReport extends CLIReport {
3024
private outputLength: number = 0;
3125

@@ -42,20 +36,20 @@ export class TTYReport extends CLIReport {
4236
private status = () => {
4337
write(
4438
'\n ' +
45-
green(this.success + ` ${this.success === 1 ? 'check' : 'checks'} passed`) +
39+
kleur.green(this.success + ` ${this.success === 1 ? 'check' : 'checks'} passed`) +
4640
(this.failure === 0 ? ` ${ICONS['tada']}` : ''),
4741
);
4842
this.outputLength++;
4943
if (this.warning > 0) {
5044
write(
5145
'\n ' +
52-
yellow(this.warning + ` ${this.warning === 1 ? 'check' : 'checks'} warned`) +
53-
grey(' (within 5% of allowed size)'),
46+
kleur.yellow(this.warning + ` ${this.warning === 1 ? 'check' : 'checks'} warned`) +
47+
kleur.grey(' (within 5% of allowed size)'),
5448
);
5549
this.outputLength++;
5650
}
5751
if (this.failure > 0) {
58-
write('\n ' + red(this.failure + ` ${this.failure === 1 ? 'check' : 'checks'} failed`));
52+
write('\n ' + kleur.red(this.failure + ` ${this.failure === 1 ? 'check' : 'checks'} failed`));
5953
this.outputLength++;
6054
}
6155
write('\n\n');
@@ -89,7 +83,12 @@ export class TTYReport extends CLIReport {
8983
processing += status.processing;
9084
}
9185

92-
const icon = failure > 0 ? red(ICONS['cross']) : processing > 0 ? dim().grey('-') : dim().green(ICONS['tick']);
86+
const icon =
87+
failure > 0
88+
? kleur.red(ICONS['cross'])
89+
: processing > 0
90+
? kleur.dim().grey('-')
91+
: kleur.dim().green(ICONS['tick']);
9392
output += ` ${icon}${this.currentLine}\n`;
9493
this.outputLength++;
9594
}

test/config-validation/config-validation.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
import test from 'ava';
17+
import tap from 'tap';
1818
import Config from '../../src/validation/Config';
1919
import { Context } from '../../src/validation/Condition';
2020

21-
test('missing package.json should fail', async (t) => {
21+
tap.test('missing package.json should fail', async (t) => {
2222
const context: Context = {
2323
packagePath: 'test/config-validation/fixtures/missing-package-json/package.json',
2424
projectPath: 'test/config-validation/fixtures/missing-package-json',
@@ -35,7 +35,7 @@ test('missing package.json should fail', async (t) => {
3535
t.is(message, `Could not read the configuration in '${context.packagePath}'`);
3636
});
3737

38-
test('unparseable package.json should fail', async (t) => {
38+
tap.test('unparseable package.json should fail', async (t) => {
3939
const context: Context = {
4040
packagePath: 'test/config-validation/fixtures/unparseable-package-json/package.json',
4141
projectPath: 'test/config-validation/fixtures/unparseable-package-json',
@@ -52,7 +52,7 @@ test('unparseable package.json should fail', async (t) => {
5252
t.is(message, `Could not parse '${context.packagePath}'`);
5353
});
5454

55-
test("missing 'filesize' key from package.json should fail", async (t) => {
55+
tap.test("missing 'filesize' key from package.json should fail", async (t) => {
5656
const context: Context = {
5757
packagePath: 'test/config-validation/fixtures/missing-configuration/package.json',
5858
projectPath: 'test/config-validation/fixtures/missing-configuration',
@@ -69,7 +69,7 @@ test("missing 'filesize' key from package.json should fail", async (t) => {
6969
t.is(message, `There is no 'filesize' configuration in '${context.packagePath}'`);
7070
});
7171

72-
test("missing path from item in 'filesize' should fail", async (t) => {
72+
tap.test("missing path from item in 'filesize' should fail", async (t) => {
7373
const context: Context = {
7474
packagePath: 'test/config-validation/fixtures/item-path-missing/package.json',
7575
projectPath: 'test/config-validation/fixtures/item-path-missing',
@@ -86,7 +86,7 @@ test("missing path from item in 'filesize' should fail", async (t) => {
8686
t.is(message, `There is no data inside the 'filesize' configuration in '${context.packagePath}'`);
8787
});
8888

89-
test("missing maxSize from item in 'filesize' should fail", async (t) => {
89+
tap.test("missing maxSize from item in 'filesize' should fail", async (t) => {
9090
const context: Context = {
9191
packagePath: 'test/config-validation/fixtures/max-size-missing/package.json',
9292
projectPath: 'test/config-validation/fixtures/max-size-missing',
@@ -103,7 +103,7 @@ test("missing maxSize from item in 'filesize' should fail", async (t) => {
103103
t.is(message, "Configuration for 'index.js' is invalid. (size unspecified)");
104104
});
105105

106-
test("missing compression from item in 'filesize' should fail", async (t) => {
106+
tap.test("missing compression from item in 'filesize' should fail", async (t) => {
107107
const context: Context = {
108108
packagePath: 'test/config-validation/fixtures/compression-missing/package.json',
109109
projectPath: 'test/config-validation/fixtures/compression-missing',
@@ -120,7 +120,7 @@ test("missing compression from item in 'filesize' should fail", async (t) => {
120120
t.is(message, "Configuration for 'index.js' is invalid. (compression values unspecified)");
121121
});
122122

123-
test('standalone configuration file when valid should pass', async (t) => {
123+
tap.test('standalone configuration file when valid should pass', async (t) => {
124124
const context: Context = {
125125
packagePath: 'test/config-validation/fixtures/standalone-config/filesize.json',
126126
projectPath: '',
@@ -137,7 +137,7 @@ test('standalone configuration file when valid should pass', async (t) => {
137137
t.is(message, null);
138138
});
139139

140-
test('standalone configuration file when path is invalid should fail', async (t) => {
140+
tap.test('standalone configuration file when path is invalid should fail', async (t) => {
141141
const context: Context = {
142142
packagePath: 'test/config-validation/fixtures/standalone-config/invalid.json',
143143
projectPath: '',

test/config-validation/track.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
import test from 'ava';
17+
import tap from 'tap';
1818
import { resolve } from 'path';
1919
import { report } from '../../src/api';
2020
import Config from '../../src/validation/Config';
2121
import { Context, SizeMapValue, SizeMap } from '../../src/validation/Condition';
2222

23-
test('including trackable items should succeed', async (t) => {
23+
tap.test('including trackable items should succeed', async (t) => {
2424
const context: Context = {
2525
packagePath: 'test/config-validation/fixtures/track/package.json',
2626
projectPath: 'test/config-validation/fixtures/track',
@@ -37,7 +37,7 @@ test('including trackable items should succeed', async (t) => {
3737
t.is(message, null);
3838
});
3939

40-
test('trackable items uses glob to find files', async (t) => {
40+
tap.test('trackable items uses glob to find files', async (t) => {
4141
const sizes: SizeMapValue = [
4242
[null, undefined], // brotli
4343
[null, undefined], // gzip
@@ -50,7 +50,7 @@ test('trackable items uses glob to find files', async (t) => {
5050
t.deepEqual(results, expected);
5151
});
5252

53-
test('trackable items uses trackFormats to restrict compression types', async (t) => {
53+
tap.test('trackable items uses trackFormats to restrict compression types', async (t) => {
5454
const sizes: SizeMapValue = [
5555
[null, undefined], // brotli
5656
[undefined, undefined], // gzip

0 commit comments

Comments
 (0)