Skip to content

Commit

Permalink
test: emit file in a random order
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan committed Mar 20, 2023
1 parent a5154cb commit 0129e9e
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions test/chunking-form/samples/emit-file/deduplicate-assets/_config.js
@@ -1,33 +1,18 @@
function asyncify(callback) {
const time = Math.round(Math.random() * 100);

return new Promise(resolve => {
setTimeout(() => {
callback();
resolve();
}, time);
});
}
module.exports = {
description: 'deduplicates asset that have the same source',
options: {
input: ['main.js'],
plugins: {
async buildStart() {
await Promise.all([
asyncify(() => this.emitFile({ type: 'asset', name: 'string1.txt', source: 'string' })),
asyncify(() => this.emitFile({ type: 'asset', name: 'string2.txt', source: 'string' })),
asyncify(() =>
this.emitFile({ type: 'asset', name: 'stringSameSource.txt', source: 'string' })
),
asyncify(() =>
this.emitFile({
type: 'asset',
name: 'sameStringAsBuffer.txt',
source: Buffer.from('string') // Test cross Buffer/string deduplication
})
)
]);
buildStart() {
// emit 'string' source in a random order
this.emitFile({ type: 'asset', name: 'stringSameSource.txt', source: 'string' });
this.emitFile({ type: 'asset', name: 'string2.txt', source: 'string' });
this.emitFile({ type: 'asset', name: 'string1.txt', source: 'string' });
this.emitFile({
type: 'asset',
name: 'sameStringAsBuffer.txt',
source: Buffer.from('string') // Test cross Buffer/string deduplication
});

// Different string source
this.emitFile({ type: 'asset', name: 'otherString.txt', source: 'otherString' });
Expand Down

0 comments on commit 0129e9e

Please sign in to comment.