From 9abe11ed7fa0171b36ec7499e48d86dcbbac7e00 Mon Sep 17 00:00:00 2001 From: Jasper De Moor Date: Wed, 30 Jan 2019 17:13:10 +0100 Subject: [PATCH] Refactor htmlnano tests to test for filesize (#2591) --- packages/core/integration-tests/test/html.js | 40 +++++++++++-------- .../core/parcel-bundler/test/sourcemaps.js | 1 - 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/packages/core/integration-tests/test/html.js b/packages/core/integration-tests/test/html.js index ed3962951e4..c498e84fc41 100644 --- a/packages/core/integration-tests/test/html.js +++ b/packages/core/integration-tests/test/html.js @@ -280,16 +280,20 @@ describe('html', function() { }); it('should minify HTML in production mode', async function() { - await bundle(path.join(__dirname, '/integration/htmlnano/index.html'), { + let inputFile = path.join(__dirname, '/integration/htmlnano/index.html'); + await bundle(inputFile, { production: true }); - let html = await fs.readFile( - path.join(__dirname, '/dist/index.html'), - 'utf8' - ); + let inputSize = (await fs.stat(inputFile)).size; + + let outputFile = path.join(__dirname, '/dist/index.html'); + let outputSize = (await fs.stat(outputFile)).size; + + assert(inputSize > outputSize); + + let html = await fs.readFile(outputFile, 'utf8'); assert(html.includes('Other page')); - assert(!html.includes('\n')); }); it('should read .htmlnanorc and minify HTML in production mode', async function() { @@ -326,19 +330,23 @@ describe('html', function() { }); it('should not minify default values inside HTML in production mode', async function() { - await bundle( - path.join(__dirname, '/integration/htmlnano-defaults-form/index.html'), - { - production: true - } + let inputFile = path.join( + __dirname, + '/integration/htmlnano-defaults-form/index.html' ); + await bundle(inputFile, { + production: true + }); - let html = await fs.readFile( - path.join(__dirname, '/dist/index.html'), - 'utf8' - ); + let inputSize = (await fs.stat(inputFile)).size; + + let outputFile = path.join(__dirname, '/dist/index.html'); + let outputSize = (await fs.stat(outputFile)).size; + + assert(inputSize > outputSize); + + let html = await fs.readFile(outputFile, 'utf8'); assert(html.includes('')); - assert(!html.includes('\n')); }); it('should not prepend the public path to assets with remote URLs', async function() { diff --git a/packages/core/parcel-bundler/test/sourcemaps.js b/packages/core/parcel-bundler/test/sourcemaps.js index 8e6b41cbea4..075a63415c5 100644 --- a/packages/core/parcel-bundler/test/sourcemaps.js +++ b/packages/core/parcel-bundler/test/sourcemaps.js @@ -1,5 +1,4 @@ const assert = require('assert'); -const fs = require('@parcel/fs'); const SourceMap = require('../src/SourceMap'); describe('sourcemaps', function() {