forked from sindresorhus/import-fresh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
40 lines (34 loc) · 895 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import path from 'path';
import test from 'ava';
import importFresh from '.';
test('main', t => {
const id = './fixture';
t.is(require(id)(), 1);
t.is(require(id)(), 2);
t.is(require(id)(), 3);
t.is(importFresh(id)(), 1);
t.is(importFresh(id)(), 1);
t.is(importFresh(id)(), 1);
t.is(require(id)(), 2);
});
test('proper parent value', t => {
const id = './fixture';
importFresh(id);
const childModule = require.cache[path.resolve(__dirname, `${id}.js`)];
t.is(childModule.parent, module);
});
test('self import', t => {
const id = './fixture-importer';
t.notThrows(() => {
importFresh(id)(id);
});
});
test('import when parent removed from cache', t => {
const id = './fixture-importer';
const importer = importFresh(id);
t.true(require.cache[importer.__filename] !== undefined);
delete require.cache[importer.__filename];
t.notThrows(() => {
importer(id);
});
});