-
Notifications
You must be signed in to change notification settings - Fork 1
/
text.spec.mjs
63 lines (50 loc) · 1.75 KB
/
text.spec.mjs
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { assertSuffixedSpecifiers } from './assert-suffixed-specifiers.fixture.mjs';
import { nextLoad } from './nextLoad.fixture.mjs';
import { nextResolve } from './nextResolve.fixture.mjs';
import { exts, load, resolve } from './text.mjs';
describe('text loader', { concurrency: true }, () => {
describe('resolve', () => {
it('should ignore files that aren’t text', async () => {
const result = await resolve('./fixture.ext', {}, nextResolve);
assert.deepEqual(result, {
format: 'unknown',
url: './fixture.ext',
});
});
it('should recognise text files', async () => {
for (const ext of Object.keys(exts)) {
const fileUrl = `./fixture${ext}`;
const result = await resolve(fileUrl, {}, nextResolve);
assert.deepEqual(result, {
format: exts[ext],
url: fileUrl,
});
}
});
it('should handle specifiers with appending data', async () => {
for (const [ext, format] of Object.entries(exts)) {
await assertSuffixedSpecifiers(resolve, `./fixture${ext}`, format);
}
});
});
describe('load', () => {
it('should ignore files that aren’t text', async () => {
const result = await load('./fixture.ext', {}, nextLoad);
assert.deepEqual(result, {
format: 'unknown',
source: '',
});
});
it('should generate a module from the text file', async () => {
for (const ext of Object.keys(exts)) {
const fileUrl = `./fixture${ext}`;
const result = await load(fileUrl, { format: 'graphql' }, nextLoad);
const { source } = await nextLoad(fileUrl, { format: 'graphql' });
assert.equal(result.format, 'module');
assert.equal(result.source, `export default \`${source}\`;`);
}
});
});
});