Skip to content
This repository was archived by the owner on Aug 4, 2021. It is now read-only.

Commit b37a7f3

Browse files
committed
Make tests compatible with rollup1.0
1 parent fa98847 commit b37a7f3

File tree

2 files changed

+44
-47
lines changed

2 files changed

+44
-47
lines changed

package-lock.json

Lines changed: 20 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/index.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,20 @@ test('Platform path.resolve(\'file-with.ext\') aliasing', (t) => {
164164
t.is(resolved, path.resolve('./test/files/folder/hipster.jsx'));
165165
});
166166

167+
const getModuleIdsFromBundle = (bundle) => {
168+
if (bundle.modules) {
169+
return Promise.resolve(bundle.modules.map(module => module.id));
170+
}
171+
return bundle.generate({ format: 'esm' }).then((generated) => {
172+
if (generated.output) {
173+
return generated.output.length ? generated.output : Object.keys(generated.output)
174+
.map(chunkName => generated.output[chunkName]);
175+
}
176+
return [generated];
177+
}).then(chunks => chunks
178+
.reduce((moduleIds, chunk) => moduleIds.concat(Object.keys(chunk.modules)), []));
179+
};
180+
167181
// Tests in Rollup
168182
test(t => rollup({
169183
input: './test/files/index.js',
@@ -173,12 +187,13 @@ test(t => rollup({
173187
numberFolder: './folder',
174188
'./numberFolder': './folder',
175189
})],
176-
}).then((stats) => {
177-
const fileNames = stats.modules.map(({ id }) => id).sort();
178-
t.is(fileNames.length, 5);
179-
t.is(fileNames[0].endsWith(path.normalize('/files/aliasMe.js')), true);
180-
t.is(fileNames[1].endsWith(path.normalize('/files/folder/anotherNumber.js')), true);
181-
t.is(fileNames[2].endsWith(path.normalize('/files/index.js')), true);
182-
t.is(fileNames[3].endsWith(path.normalize('/files/localAliasMe.js')), true);
183-
t.is(fileNames[4].endsWith(path.normalize('/files/nonAliased.js')), true);
184-
}));
190+
}).then(getModuleIdsFromBundle)
191+
.then((moduleIds) => {
192+
moduleIds.sort();
193+
t.is(moduleIds.length, 5);
194+
t.is(moduleIds[0].endsWith(path.normalize('/files/aliasMe.js')), true);
195+
t.is(moduleIds[1].endsWith(path.normalize('/files/folder/anotherNumber.js')), true);
196+
t.is(moduleIds[2].endsWith(path.normalize('/files/index.js')), true);
197+
t.is(moduleIds[3].endsWith(path.normalize('/files/localAliasMe.js')), true);
198+
t.is(moduleIds[4].endsWith(path.normalize('/files/nonAliased.js')), true);
199+
}));

0 commit comments

Comments
 (0)