-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6a865e
commit bf59bfd
Showing
27 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const path = require('path'); | ||
const rollup = require('../../dist/rollup'); | ||
const { extend, runTestSuiteWithSamples } = require('../utils.js'); | ||
const assert = require('assert'); | ||
|
||
runTestSuiteWithSamples('file hashes', path.resolve(__dirname, 'samples'), (dir, config) => { | ||
(config.skip ? describe.skip : config.solo ? describe.only : describe)( | ||
path.basename(dir) + ': ' + config.description, | ||
() => { | ||
it(`generates correct hashes`, () => { | ||
process.chdir(dir); | ||
return Promise.all( | ||
[config.options1, config.options2].map(options => | ||
rollup | ||
.rollup(options) | ||
.then(bundle => | ||
bundle.generate( | ||
extend( | ||
{ format: 'esm', chunkFileNames: '[hash]', entryFileNames: '[hash]' }, | ||
options.output | ||
) | ||
) | ||
) | ||
.then(mapGeneratedToHashMap) | ||
) | ||
).then(([hashMap1, hashMap2]) => { | ||
for (const name of config.expectedEqualHashes || []) { | ||
checkChunkExists(hashMap1, hashMap2, name); | ||
assert.equal( | ||
hashMap1[name], | ||
hashMap2[name], | ||
`Expected hashes for chunk containing "${name}" to be equal but they were different.` | ||
); | ||
} | ||
for (const name of config.expectedDifferentHashes || []) { | ||
checkChunkExists(hashMap1, hashMap2, name); | ||
assert.notEqual( | ||
hashMap1[name], | ||
hashMap2[name], | ||
`Expected hashes for chunk containing "${name}" to be different but they were equal.` | ||
); | ||
} | ||
}); | ||
}); | ||
} | ||
); | ||
}); | ||
|
||
function mapGeneratedToHashMap(generated) { | ||
const hashMap = {}; | ||
const dirLength = process.cwd().length + 1; | ||
for (const chunk of generated.output) { | ||
for (const moduleName of Object.keys(chunk.modules)) { | ||
hashMap[moduleName.slice(dirLength)] = chunk.fileName; | ||
} | ||
} | ||
return hashMap; | ||
} | ||
|
||
function checkChunkExists(hashMap1, hashMap2, name) { | ||
[hashMap1, hashMap2].forEach((hashMap, index) => | ||
assert.ok( | ||
hashMap[name], | ||
`Bundle ${index} did not contain a chunk containing module "${name}", found chunks for modules: ${Object.keys( | ||
hashMap | ||
).join(', ')}` | ||
) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
solo: true, | ||
description: 'creates different hashes if the content is equal but the generated exports differ', | ||
options1: { | ||
input: ['main1', 'other'] | ||
}, | ||
options2: { | ||
input: ['main2', 'other'] | ||
}, | ||
expectedDifferentHashes: ['dep.js'] | ||
}; |
5 changes: 5 additions & 0 deletions
5
test/file-hashes/samples/respects-exports/_expected/amd/generated-chunk.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
define(function () { 'use strict'; | ||
|
||
console.log('main4'); | ||
|
||
}); |
5 changes: 5 additions & 0 deletions
5
test/file-hashes/samples/respects-exports/_expected/amd/generated-chunk2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
define(function () { 'use strict'; | ||
|
||
console.log('main5'); | ||
|
||
}); |
7 changes: 7 additions & 0 deletions
7
test/file-hashes/samples/respects-exports/_expected/amd/main1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
define(['require'], function (require) { 'use strict'; | ||
|
||
console.log('main1'); | ||
new Promise(function (resolve, reject) { require(['./generated-chunk.js'], resolve, reject) }); | ||
new Promise(function (resolve, reject) { require(['./generated-chunk2.js'], resolve, reject) }); | ||
|
||
}); |
5 changes: 5 additions & 0 deletions
5
test/file-hashes/samples/respects-exports/_expected/amd/main2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
define(function () { 'use strict'; | ||
|
||
console.log('main2'); | ||
|
||
}); |
5 changes: 5 additions & 0 deletions
5
test/file-hashes/samples/respects-exports/_expected/amd/main3.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
define(function () { 'use strict'; | ||
|
||
console.log('main3'); | ||
|
||
}); |
3 changes: 3 additions & 0 deletions
3
test/file-hashes/samples/respects-exports/_expected/cjs/generated-chunk.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
console.log('main4'); |
3 changes: 3 additions & 0 deletions
3
test/file-hashes/samples/respects-exports/_expected/cjs/generated-chunk2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
console.log('main5'); |
5 changes: 5 additions & 0 deletions
5
test/file-hashes/samples/respects-exports/_expected/cjs/main1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
console.log('main1'); | ||
Promise.resolve(require('./generated-chunk.js')); | ||
Promise.resolve(require('./generated-chunk2.js')); |
3 changes: 3 additions & 0 deletions
3
test/file-hashes/samples/respects-exports/_expected/cjs/main2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
console.log('main2'); |
3 changes: 3 additions & 0 deletions
3
test/file-hashes/samples/respects-exports/_expected/cjs/main3.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
console.log('main3'); |
1 change: 1 addition & 0 deletions
1
test/file-hashes/samples/respects-exports/_expected/es/generated-chunk.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('main4'); |
1 change: 1 addition & 0 deletions
1
test/file-hashes/samples/respects-exports/_expected/es/generated-chunk2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('main5'); |
3 changes: 3 additions & 0 deletions
3
test/file-hashes/samples/respects-exports/_expected/es/main1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
console.log('main1'); | ||
import('./generated-chunk.js'); | ||
import('./generated-chunk2.js'); |
1 change: 1 addition & 0 deletions
1
test/file-hashes/samples/respects-exports/_expected/es/main2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('main2'); |
1 change: 1 addition & 0 deletions
1
test/file-hashes/samples/respects-exports/_expected/es/main3.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('main3'); |
10 changes: 10 additions & 0 deletions
10
test/file-hashes/samples/respects-exports/_expected/system/generated-chunk.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
System.register([], function (exports, module) { | ||
'use strict'; | ||
return { | ||
execute: function () { | ||
|
||
console.log('main4'); | ||
|
||
} | ||
}; | ||
}); |
10 changes: 10 additions & 0 deletions
10
test/file-hashes/samples/respects-exports/_expected/system/generated-chunk2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
System.register([], function (exports, module) { | ||
'use strict'; | ||
return { | ||
execute: function () { | ||
|
||
console.log('main5'); | ||
|
||
} | ||
}; | ||
}); |
12 changes: 12 additions & 0 deletions
12
test/file-hashes/samples/respects-exports/_expected/system/main1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
System.register([], function (exports, module) { | ||
'use strict'; | ||
return { | ||
execute: function () { | ||
|
||
console.log('main1'); | ||
module.import('./generated-chunk.js'); | ||
module.import('./generated-chunk2.js'); | ||
|
||
} | ||
}; | ||
}); |
10 changes: 10 additions & 0 deletions
10
test/file-hashes/samples/respects-exports/_expected/system/main2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
System.register([], function (exports, module) { | ||
'use strict'; | ||
return { | ||
execute: function () { | ||
|
||
console.log('main2'); | ||
|
||
} | ||
}; | ||
}); |
10 changes: 10 additions & 0 deletions
10
test/file-hashes/samples/respects-exports/_expected/system/main3.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
System.register([], function (exports, module) { | ||
'use strict'; | ||
return { | ||
execute: function () { | ||
|
||
console.log('main3'); | ||
|
||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const mightNotBeImported = 42; | ||
console.log(mightNotBeImported); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {mightNotBeImported} from './dep'; | ||
|
||
console.log('main1', mightNotBeImported); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import './dep'; | ||
|
||
console.log('main2'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import './dep'; | ||
|
||
console.log('other'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters