Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update testing setup to use jest #53

Merged
merged 13 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/fixtures/input
5 changes: 4 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
module.exports = {
"extends": "eslint:recommended",
"plugins": ["jest"],
"parserOptions": {
"ecmaVersion": 6
},
"env": {
"node": true
"node": true,
"es6": true,
"jest": true
},
"rules": {
}
Expand Down
7 changes: 6 additions & 1 deletion lib/summarize.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ function compress(content) {
return pify(zlib.deflate)(content, { level: 9 });
}

function normalizeLineEndings(content) {
return content.replace(/(\r\n|\n|\r)/gm, "\n");
}

/**
* Given a single json file from broccoli-concat calculate the size summary (uglified/compressed) of all referenced files
*
Expand All @@ -36,14 +40,15 @@ module.exports = function summarize(summaryPath) {
let fileContents = {};
fileNames.forEach((filename) => {
try {
fileContents[filename] = fs.readFileSync(path.join(dirname, basename, filename), 'UTF8');
fileContents[filename] = normalizeLineEndings(fs.readFileSync(path.join(dirname, basename, filename), 'UTF8'));
} catch(e) {
if (e !== null && typeof e === 'object' && e.code === 'ENOENT') {
// To provide backwards compability we support missing files, that are referenced in the metadata.
// Typically these missing files are simple "optional" build files.
//
// Although broccoli-concat can properly handle this scenario, this
// library should be maximally compatible for the time being.
// eslint-disable-next-line no-console
console.warn(`warning: '${filename}' is missing, and will be reported as an empty file. `);
fileContents[filename] = '';
} else {
Expand Down
19 changes: 12 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"description": "",
"main": "lib/index.js",
"scripts": {
"test": "mocha --recursive test/**/*-test.js"
"test": "eslint . && jest"
},
"repository": {
"type": "git",
Expand All @@ -26,19 +26,24 @@
"pify": "^4.0.0",
"terser": "^3.10.11",
"walk-sync": "^0.3.1",
"workerpool": "^2.3.1",
"workerpool": "^5.0.4",
"zlib": "^1.0.5"
},
"devDependencies": {
"chai": "^4.0.2",
"chai-as-promised": "^7.1.1",
"chai-files": "^1.4.0",
"eslint": "^5.16.0",
"eslint-plugin-jest": "^22.21.0",
"html-validator": "^3.0.6",
"mocha": "^3.4.2",
"mocha-eslint": "^4.0.0",
"jest": "^22.4.3",
"tmp": "^0.0.33"
},
"jest": {
"verbose": true,
"testURL": "http://localhost/"
},
"engines": {
"node": "6.* || 8.* || >= 10.*"
},
"volta": {
"node": "6.17.1"
}
}
5 changes: 0 additions & 5 deletions test/.eslintrc.js

This file was deleted.

94 changes: 94 additions & 0 deletions test/acceptance/__snapshots__/cli.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CLI generates expected output 1`] = `
"{
\\"outputFile\\": \\"/assets/test-app.js\\",
\\"files\\": [
{
\\"relativePath\\": \\"test-app/app.js\\",
\\"sizes\\": {
\\"raw\\": 606,
\\"uglified\\": 375,
\\"compressed\\": 119.82860520094562
}
},
{
\\"relativePath\\": \\"test-app/initializers/app-version.js\\",
\\"sizes\\": {
\\"raw\\": 510,
\\"uglified\\": 311,
\\"compressed\\": 99.37785657998424
}
},
{
\\"relativePath\\": \\"test-app/initializers/container-debug-adapter.js\\",
\\"sizes\\": {
\\"raw\\": 590,
\\"uglified\\": 428,
\\"compressed\\": 136.76438140267928
}
},
{
\\"relativePath\\": \\"test-app/initializers/export-application-global.js\\",
\\"sizes\\": {
\\"raw\\": 1377,
\\"uglified\\": 684,
\\"compressed\\": 218.56737588652481
}
},
{
\\"relativePath\\": \\"test-app/resolver.js\\",
\\"sizes\\": {
\\"raw\\": 231,
\\"uglified\\": 154,
\\"compressed\\": 49.20961386918834
}
},
{
\\"relativePath\\": \\"test-app/router.js\\",
\\"sizes\\": {
\\"raw\\": 425,
\\"uglified\\": 264,
\\"compressed\\": 84.35933806146572
}
},
{
\\"relativePath\\": \\"test-app/templates/application.js\\",
\\"sizes\\": {
\\"raw\\": 399,
\\"uglified\\": 322,
\\"compressed\\": 102.89282899921197
}
}
]
}"
`;

exports[`CLI generates expected output 2`] = `
"{
\\"outputFile\\": \\"/assets/vendor.css\\",
\\"files\\": []
}"
`;

exports[`CLI generates expected output 3`] = `
"{
\\"outputFile\\": \\"/assets/test-support.css\\",
\\"files\\": [
{
\\"relativePath\\": \\"vendor/qunit/qunit.css\\",
\\"sizes\\": {
\\"raw\\": 7875,
\\"compressed\\": 2123.0700712589073
}
},
{
\\"relativePath\\": \\"vendor/ember-qunit/test-container-styles.css\\",
\\"sizes\\": {
\\"raw\\": 544,
\\"compressed\\": 146.6603325415677
}
}
]
}"
`;
19 changes: 8 additions & 11 deletions test/acceptance/cli-test.js → test/acceptance/cli.test.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
'use strict';

const chai = require('chai');
const expect = chai.expect;
const tmp = require('tmp');
const chaiFiles = require('chai-files');
const file = chaiFiles.file;
const path = require('path');
const cp = require('child_process');
const fs = require('fs-extra');
const validate = require('html-validator');
const copyFixtures = require('../helpers/copy-fixtures');

const inputFixturePath = 'test/fixtures/input';
const outputFixturePath = 'test/fixtures/output';

const inputFiles = ['1-test-app.js', '3-vendor.css', '8-test-support.css'];

const originalCwd = process.cwd();
let tmpPath;
let outPath;

chai.use(chaiFiles);
function file(dir) {
return fs.readFileSync(dir, 'utf-8');
}

function run() {
let stdout = '';
Expand Down Expand Up @@ -67,20 +64,20 @@ describe('CLI', function() {
let exitCode = result.exitCode;
let stdout = result.stdout;

expect(exitCode).to.equal(0);
expect(stdout).to.contain(`visit file://${outPath}/index.html`);
expect(exitCode).toEqual(0);
expect(stdout).toContain(`visit file://${outPath}/index.html`);

// write .out.json files
inputFiles.forEach((inputFile) => {
let outputFile = `${inputFile}.out.json`;
expect(file(path.join(outPath, outputFile))).to.equal(file(path.join(outputFixturePath, outputFile)));
expect(file(path.join(outPath, outputFile))).toMatchSnapshot();
});

// copies static output files
expect(file(path.join(outPath, 'index.html'))).to.exist;
expect(file(path.join(outPath, 'index.html'))).toBeTruthy();

let data = fs.readFileSync(`${outPath}/index.html`, 'UTF8');
expect(data).to.contain('var SUMMARY = {');
expect(data).toContain('var SUMMARY = {');

return validate({
data,
Expand Down
8 changes: 0 additions & 8 deletions test/eslint-test.js

This file was deleted.

61 changes: 0 additions & 61 deletions test/fixtures/output/1-test-app.js.out.json

This file was deleted.

4 changes: 0 additions & 4 deletions test/fixtures/output/3-vendor.css.out.json

This file was deleted.

19 changes: 0 additions & 19 deletions test/fixtures/output/8-test-support.css.out.json

This file was deleted.

Loading