1 | const test = require('ava');
|
2 | const { join } = require('path');
|
3 | const { tmpdir } = require('os');
|
4 | const { writeFileSync, unlinkSync } = require('fs');
|
5 | const { read } = require('./filesystem');
|
6 |
|
7 | test('it returns data from cache', async assert => {
|
8 | const dir = tmpdir();
|
9 | const filepath = join(dir, 'filesystem-test-cache-true.html');
|
10 | writeFileSync(filepath, '<div>foo</div>');
|
11 | const content1 = await read(filepath, { cache: true });
|
12 | assert.deepEqual(content1, '<div>foo</div>');
|
13 | writeFileSync(filepath, '<div>bar</div>');
|
14 | const content2 = await read(filepath, { cache: true });
|
15 | assert.deepEqual(content2, '<div>foo</div>');
|
16 | unlinkSync(filepath);
|
17 | });
|
18 |
|
19 | test('it reads data multiple time without cache', async assert => {
|
20 | const dir = tmpdir();
|
21 | const filepath = join(dir, 'filesystem-test-cache-false.html');
|
22 | writeFileSync(filepath, '<div>foo</div>');
|
23 | const content1 = await read(filepath, { cache: false });
|
24 | assert.deepEqual(content1, '<div>foo</div>');
|
25 | writeFileSync(filepath, '<div>bar</div>');
|
26 | const content2 = await read(filepath, { cache: false });
|
27 | assert.deepEqual(content2, '<div>bar</div>');
|
28 | unlinkSync(filepath);
|
29 | });
|