Skip to content

Commit

Permalink
Add integration test to verify dependency tracking of custom extenstions
Browse files Browse the repository at this point in the history
  • Loading branch information
lo1tuma committed Apr 5, 2019
1 parent fa6f6b4 commit 24fcf7e
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
sources: ['source.custom-ext']
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
8 changes: 8 additions & 0 deletions test/fixture/watcher/with-custom-ext-dependencies/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

const fs = require('fs');

require.extensions['.custom-ext'] = function (module, filename) {
const content = fs.readFileSync(filename, 'utf8');
module._compile(content, filename);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
'use strict';
module.exports = true;
6 changes: 6 additions & 0 deletions test/fixture/watcher/with-custom-ext-dependencies/test-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import test from '../../../..';
import dependency from './source.custom-ext';

test('works', t => {
t.truthy(dependency);
});
5 changes: 5 additions & 0 deletions test/fixture/watcher/with-custom-ext-dependencies/test-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import test from '../../../..';

test('works', t => {
t.pass();
});
24 changes: 24 additions & 0 deletions test/integration/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,30 @@ test('watcher reruns test files when source dependencies change', t => {
});
});

test('watcher reruns ONLY test files that depend on a changed source with custom extension', t => {
let killed = false;

const child = execCli(['--verbose', '--require', './setup.js', '--watch', 'test-*.js'], {dirname: 'fixture/watcher/with-custom-ext-dependencies', env: {CI: ''}}, err => {
t.ok(killed);
t.ifError(err);
t.end();
});

let buffer = '';
let passedFirst = false;
child.stdout.on('data', str => {
buffer += str;
if (buffer.includes('2 tests passed') && !passedFirst) {
touch.sync(path.join(__dirname, '../fixture/watcher/with-custom-ext-dependencies/source.custom-ext'));
buffer = '';
passedFirst = true;
} else if (buffer.includes('1 test passed') && !killed) {
child.kill();
killed = true;
}
});
});

test('watcher does not rerun test files when they write snapshot files', t => {
let killed = false;

Expand Down

0 comments on commit 24fcf7e

Please sign in to comment.