UNPKG

1.94 kBJavaScriptView Raw
1// @flow strict-local
2
3import assert from 'assert';
4import Asset, {createAsset} from '../src/InternalAsset';
5import {createEnvironment} from '../src/Environment';
6import {DEFAULT_OPTIONS} from './utils';
7
8const stats = {time: 0, size: 0};
9
10describe('InternalAsset', () => {
11 it('only includes connected files once per filePath', () => {
12 let asset = new Asset({
13 value: createAsset({
14 filePath: '/foo/asset.js',
15 env: createEnvironment(),
16 stats,
17 type: 'js',
18 isSource: true
19 }),
20 options: DEFAULT_OPTIONS
21 });
22 asset.addIncludedFile({filePath: '/foo/file', hash: 'abc'});
23 asset.addIncludedFile({filePath: '/foo/file', hash: 'bcd'});
24 assert.deepEqual(asset.getIncludedFiles(), [
25 {
26 filePath: '/foo/file',
27 hash: 'bcd'
28 }
29 ]);
30 });
31
32 it('only includes dependencies once per id', () => {
33 let asset = new Asset({
34 value: createAsset({
35 filePath: '/foo/asset.js',
36 env: createEnvironment(),
37 stats,
38 type: 'js',
39 isSource: true
40 }),
41 options: DEFAULT_OPTIONS
42 });
43
44 asset.addDependency({moduleSpecifier: './foo'});
45 asset.addDependency({moduleSpecifier: './foo'});
46 let dependencies = asset.getDependencies();
47 assert(dependencies.length === 1);
48 assert(dependencies[0].moduleSpecifier === './foo');
49 });
50
51 it('includes different dependencies if their id differs', () => {
52 let asset = new Asset({
53 value: createAsset({
54 filePath: '/foo/asset.js',
55 env: createEnvironment(),
56 stats,
57 type: 'js',
58 isSource: true
59 }),
60 options: DEFAULT_OPTIONS
61 });
62
63 asset.addDependency({moduleSpecifier: './foo'});
64 asset.addDependency({
65 moduleSpecifier: './foo',
66 env: {context: 'web-worker', engines: {}}
67 });
68 let dependencies = asset.getDependencies();
69 assert(dependencies.length === 2);
70 });
71});