|
2 | 2 |
|
3 | 3 | import assert from 'assert';
|
4 | 4 | import path from 'path';
|
5 |
| -import {bundle} from '@parcel/test-utils'; |
| 5 | +import {bundle, fsFixture, overlayFS} from '@parcel/test-utils'; |
| 6 | +import type {BundleGraph, BundleGroup, PackagedBundle} from '@parcel/types'; |
6 | 7 |
|
7 | 8 | describe('BundleGraph', () => {
|
8 | 9 | it('can traverse assets across bundles and contexts', async () => {
|
@@ -77,4 +78,67 @@ describe('BundleGraph', () => {
|
77 | 78 | },
|
78 | 79 | ]);
|
79 | 80 | });
|
| 81 | + |
| 82 | + describe('getBundlesInBundleGroup', () => { |
| 83 | + let bundleGraph: BundleGraph<PackagedBundle>; |
| 84 | + let bundleGroup: BundleGroup; |
| 85 | + let dir = path.join(__dirname, 'get-bundles-in-bundle-group'); |
| 86 | + |
| 87 | + before(async () => { |
| 88 | + await overlayFS.mkdirp(dir); |
| 89 | + |
| 90 | + await fsFixture(overlayFS, dir)` |
| 91 | + logo.svg: |
| 92 | + <svg></svg> |
| 93 | +
|
| 94 | + index.jsx: |
| 95 | + import logo from 'data-url:./logo.svg'; |
| 96 | +
|
| 97 | + yarn.lock: {} |
| 98 | + `; |
| 99 | + |
| 100 | + bundleGraph = await bundle(path.join(dir, 'index.jsx'), { |
| 101 | + inputFS: overlayFS, |
| 102 | + }); |
| 103 | + |
| 104 | + bundleGroup = bundleGraph.getBundleGroupsContainingBundle( |
| 105 | + bundleGraph.getBundles({includeInline: true})[0], |
| 106 | + )[0]; |
| 107 | + }); |
| 108 | + |
| 109 | + after(async () => { |
| 110 | + await overlayFS.rimraf(dir); |
| 111 | + }); |
| 112 | + |
| 113 | + it('does not return inlineAssets by default', () => { |
| 114 | + const bundles = bundleGraph.getBundlesInBundleGroup(bundleGroup); |
| 115 | + |
| 116 | + assert.deepEqual( |
| 117 | + bundles.map(b => b.bundleBehavior), |
| 118 | + [null], |
| 119 | + ); |
| 120 | + }); |
| 121 | + |
| 122 | + it('does not return inlineAssets when requested', () => { |
| 123 | + const bundles = bundleGraph.getBundlesInBundleGroup(bundleGroup, { |
| 124 | + includeInline: false, |
| 125 | + }); |
| 126 | + |
| 127 | + assert.deepEqual( |
| 128 | + bundles.map(b => b.bundleBehavior), |
| 129 | + [null], |
| 130 | + ); |
| 131 | + }); |
| 132 | + |
| 133 | + it('returns inlineAssets when requested', () => { |
| 134 | + const bundles = bundleGraph.getBundlesInBundleGroup(bundleGroup, { |
| 135 | + includeInline: true, |
| 136 | + }); |
| 137 | + |
| 138 | + assert.deepEqual( |
| 139 | + bundles.map(b => b.bundleBehavior), |
| 140 | + [null, 'inline'], |
| 141 | + ); |
| 142 | + }); |
| 143 | + }); |
80 | 144 | });
|
0 commit comments