Skip to content

Commit

Permalink
Enable contentHashing test
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Binns-Smith committed Aug 16, 2019
1 parent 97c40e8 commit c56dbd7
Showing 1 changed file with 30 additions and 32 deletions.
62 changes: 30 additions & 32 deletions packages/core/integration-tests/test/contentHashing.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,70 @@
const assert = require('assert');
const path = require('path');
const {bundle, rimraf, ncp, inputFS: fs} = require('@parcel/test-utils');
import assert from 'assert';
import path from 'path';
import {bundle as _bundle, distDir, inputFS as fs} from '@parcel/test-utils';

describe.skip('content hashing', function() {
function bundle(path) {
return _bundle(path, {
disableCache: false,
inputFS: fs,
// These tests must use the real fs as they rely on the watcher
outputFS: fs
});
}

describe('content hashing', function() {
beforeEach(async function() {
await rimraf(path.join(__dirname, '/input'));
await fs.rimraf(path.join(__dirname, '/input'));
});

it('should update content hash when content changes', async function() {
await ncp(
await fs.ncp(
path.join(__dirname, '/integration/html-css'),
path.join(__dirname, '/input')
);

await bundle(path.join(__dirname, '/input/index.html'), {
production: true
});
let bundleHtml = () => bundle(path.join(__dirname, '/input/index.html'));
await bundleHtml();

let html = await fs.readFile(
path.join(__dirname, '/dist/index.html'),
'utf8'
);
let html = await fs.readFile(path.join(distDir, 'index.html'), 'utf8');
let filename = html.match(
/<link rel="stylesheet" href="[/\\]{1}(input\.[a-f0-9]+\.css)">/
)[1];
assert(await fs.exists(path.join(__dirname, '/dist/', filename)));
assert(await fs.exists(path.join(distDir, filename)));

await fs.writeFile(
path.join(__dirname, '/input/index.css'),
'body { background: green }'
);
await bundleHtml();

await bundle(path.join(__dirname, '/input/index.html'), {
production: true
});

html = await fs.readFile(path.join(__dirname, '/dist/index.html'), 'utf8');
html = await fs.readFile(path.join(distDir, 'index.html'), 'utf8');
let newFilename = html.match(
/<link rel="stylesheet" href="[/\\]{1}(input\.[a-f0-9]+\.css)">/
)[1];
assert(await fs.exists(path.join(__dirname, '/dist/', newFilename)));
assert(await fs.exists(path.join(distDir, newFilename)));

assert.notEqual(filename, newFilename);
});

it('should update content hash when raw asset changes', async function() {
await ncp(
await fs.ncp(
path.join(__dirname, '/integration/import-raw'),
path.join(__dirname, '/input')
);

await bundle(path.join(__dirname, '/input/index.js'), {
production: true
});
let bundleJs = () => bundle(path.join(__dirname, '/input/index.js'));
await bundleJs();

let js = await fs.readFile(path.join(__dirname, '/dist/index.js'), 'utf8');
let js = await fs.readFile(path.join(distDir, 'index.js'), 'utf8');
let filename = js.match(/\/(test\.[0-9a-f]+\.txt)/)[1];
assert(await fs.exists(path.join(__dirname, '/dist/', filename)));
assert(await fs.exists(path.join(distDir, filename)));

await fs.writeFile(path.join(__dirname, '/input/test.txt'), 'hello world');
await bundleJs();

await bundle(path.join(__dirname, '/input/index.js'), {
production: true
});

js = await fs.readFile(path.join(__dirname, '/dist/index.js'), 'utf8');
js = await fs.readFile(path.join(distDir, 'index.js'), 'utf8');
let newFilename = js.match(/\/(test\.[0-9a-f]+\.txt)/)[1];
assert(await fs.exists(path.join(__dirname, '/dist/', newFilename)));
assert(await fs.exists(path.join(distDir, newFilename)));

assert.notEqual(filename, newFilename);
});
Expand Down

0 comments on commit c56dbd7

Please sign in to comment.