-
Notifications
You must be signed in to change notification settings - Fork 1
/
media.spec.mjs
62 lines (50 loc) · 1.69 KB
/
media.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
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 './media.mjs';
describe('media loader', { concurrency: true }, () => {
describe('resolve', () => {
it('should ignore unrecognised files', async () => {
const result = await resolve('./fixture.ext', {}, nextResolve);
assert.deepEqual(result, {
format: 'unknown',
url: './fixture.ext',
});
});
it('should recognise media files', async () => {
for (const ext of exts) {
const fileUrl = `./fixture.${ext}`;
const result = await resolve(fileUrl, {}, nextResolve);
assert.deepEqual(result, {
format: 'media',
url: fileUrl,
});
}
});
it('should handle specifiers with appending data', async () => {
for (const ext of exts) await assertSuffixedSpecifiers(resolve, `./fixture.${ext}`, 'media');
});
});
describe('load', () => {
it('should ignore unrecognised files', async () => {
const result = await load('./fixture.ext', {}, nextLoad);
assert.deepEqual(result, {
format: 'unknown',
source: '',
});
});
it('should return the resolved URL for the media file', async () => {
for (const ext of exts) {
const fileUrl = `./fixture.${ext}`;
const result = await load(fileUrl, { format: 'media' }, () => { throw new Error('media file should not be read from disk'); });
assert.deepEqual(result, {
format: 'module',
shortCircuit: true,
source: `export default '${fileUrl}';`,
});
}
});
});
});