Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Unify form and function test setup; allow for function tests to be in nested directories * Enable chunking form tests be in nested directories and unify setup * Enable CLI tests be in nested directories and unify setup * Enable sourcemap tests to be in nested directories and unify setup * Unify options format for function tests and fix some references to output options in warnings
- Loading branch information
1 parent
4fc927b
commit e093195
Showing
17 changed files
with
363 additions
and
404 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
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
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
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
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 |
---|---|---|
@@ -1,95 +1,80 @@ | ||
const path = require('path'); | ||
const assert = require('assert'); | ||
const sander = require('sander'); | ||
const fixturify = require('fixturify'); | ||
const rollup = require('../../dist/rollup'); | ||
const { extend, loadConfig } = require('../utils.js'); | ||
|
||
const samples = path.resolve(__dirname, 'samples'); | ||
const { extend, runTestSuiteWithSamples } = require('../utils.js'); | ||
|
||
const FORMATS = ['es', 'cjs', 'amd', 'system']; | ||
|
||
describe('chunking form', () => { | ||
sander | ||
.readdirSync(samples) | ||
.sort() | ||
.forEach(dir => { | ||
if (dir[0] === '.') return; // .DS_Store... | ||
|
||
const config = loadConfig(samples + '/' + dir + '/_config.js'); | ||
|
||
if (!config || (config.skipIfWindows && process.platform === 'win32')) return; | ||
if (!config.options) { | ||
config.options = {}; | ||
} | ||
|
||
const inputOptions = extend( | ||
{}, | ||
{ | ||
input: [samples + '/' + dir + '/main.js'], | ||
experimentalCodeSplitting: true, | ||
onwarn: msg => { | ||
if (/No name was provided for/.test(msg)) return; | ||
if (/as external dependency/.test(msg)) return; | ||
console.error(msg); | ||
} | ||
}, | ||
config.options | ||
); | ||
|
||
(config.skip ? describe.skip : config.solo ? describe.only : describe)(dir, () => { | ||
let promise; | ||
const createBundle = () => promise || (promise = rollup.rollup(inputOptions)); | ||
|
||
FORMATS.forEach(format => { | ||
it('generates ' + format, () => { | ||
process.chdir(samples + '/' + dir); | ||
runTestSuiteWithSamples('chunking form', path.resolve(__dirname, 'samples'), (dir, config) => { | ||
(config.skip ? describe.skip : config.solo ? describe.only : describe)( | ||
path.basename(dir) + ': ' + config.description, | ||
() => { | ||
let rollupPromise; | ||
|
||
return createBundle().then(bundle => { | ||
const outputOptions = extend( | ||
{}, | ||
FORMATS.forEach(format => | ||
it('generates ' + format, () => { | ||
process.chdir(dir); | ||
return ( | ||
rollupPromise || | ||
(rollupPromise = rollup.rollup( | ||
extend( | ||
{ | ||
dir: samples + '/' + dir + '/_actual/' + format, | ||
input: [dir + '/main.js'], | ||
experimentalCodeSplitting: true, | ||
onwarn: msg => { | ||
if (/No name was provided for/.test(msg)) return; | ||
if (/as external dependency/.test(msg)) return; | ||
console.error(msg); | ||
} | ||
}, | ||
config.options || {} | ||
) | ||
)) | ||
).then(bundle => | ||
generateAndTestBundle( | ||
bundle, | ||
extend( | ||
{ | ||
dir: dir + '/_actual/' + format, | ||
format | ||
}, | ||
inputOptions.output || {} | ||
); | ||
|
||
sander.rimrafSync(outputOptions.dir); | ||
(config.options || {}).output || {} | ||
), | ||
dir + '/_expected/' + format, | ||
config | ||
) | ||
); | ||
}) | ||
); | ||
} | ||
); | ||
}); | ||
|
||
return bundle.write(outputOptions).then(() => { | ||
const actualFiles = fixturify.readSync(path.join(samples, dir, '_actual', format)); | ||
function generateAndTestBundle(bundle, outputOptions, expectedDir) { | ||
return bundle.write(outputOptions).then(() => { | ||
const actualFiles = fixturify.readSync(outputOptions.dir); | ||
|
||
let expectedFiles; | ||
try { | ||
expectedFiles = fixturify.readSync(path.join(samples, dir, '_expected', format)); | ||
} catch (err) { | ||
expectedFiles = []; | ||
} | ||
let expectedFiles; | ||
try { | ||
expectedFiles = fixturify.readSync(expectedDir); | ||
} catch (err) { | ||
expectedFiles = []; | ||
} | ||
assertFilesAreEqual(actualFiles, expectedFiles, []); | ||
}); | ||
} | ||
|
||
(function recurse(actualFiles, expectedFiles, dirs) { | ||
const fileNames = Array.from( | ||
new Set(Object.keys(actualFiles).concat(Object.keys(expectedFiles))) | ||
); | ||
fileNames.forEach(fileName => { | ||
const sections = dirs.concat(fileName); | ||
if ( | ||
typeof actualFiles[fileName] === 'object' && | ||
typeof expectedFiles[fileName] === 'object' | ||
) { | ||
return recurse(actualFiles[fileName], expectedFiles[fileName], sections); | ||
} | ||
assert.strictEqual( | ||
actualFiles[fileName], | ||
expectedFiles[fileName], | ||
'Unexpected output for ' + sections.join('/') | ||
); | ||
}); | ||
})(actualFiles, expectedFiles, []); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
function assertFilesAreEqual(actualFiles, expectedFiles, dirs) { | ||
Object.keys(Object.assign({}, actualFiles, expectedFiles)).forEach(fileName => { | ||
const pathSegments = dirs.concat(fileName); | ||
if (typeof actualFiles[fileName] === 'object' && typeof expectedFiles[fileName] === 'object') { | ||
return assertFilesAreEqual(actualFiles[fileName], expectedFiles[fileName], pathSegments); | ||
} | ||
assert.strictEqual( | ||
actualFiles[fileName], | ||
expectedFiles[fileName], | ||
'Unexpected output for ' + pathSegments.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
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
Oops, something went wrong.