import deindent from '../src/utils/deindent.js'; import assert from 'assert'; import { svelte, env, setupHtmlEqual } from './helpers.js'; function testAmd ( code, expectedId, dependencies, html ) { const fn = new Function( 'define', code ); return env().then( window => { function define ( id, deps, factory ) { assert.equal( id, expectedId ); assert.deepEqual( deps, Object.keys( dependencies ) ); const SvelteComponent = factory( ...Object.keys( dependencies ).map( key => dependencies[ key ] ) ); const main = window.document.body.querySelector( 'main' ); const component = new SvelteComponent({ target: main }); assert.htmlEqual( main.innerHTML, html ); component.teardown(); } define.amd = true; fn( define ); }); } function testCjs ( code, dependencyById, html ) { const fn = new Function( 'module', 'exports', 'require', code ); return env().then( window => { const module = { exports: {} }; const require = id => { return dependencyById[ id ]; }; fn( module, module.exports, require ); const SvelteComponent = module.exports; const main = window.document.body.querySelector( 'main' ); const component = new SvelteComponent({ target: main }); assert.htmlEqual( main.innerHTML, html ); component.teardown(); }); } function testIife ( code, name, globals, html ) { const fn = new Function( Object.keys( globals ), `${code}\n\nreturn ${name};` ); return env().then( window => { const SvelteComponent = fn( ...Object.keys( globals ).map( key => globals[ key ] ) ); const main = window.document.body.querySelector( 'main' ); const component = new SvelteComponent({ target: main }); assert.htmlEqual( main.innerHTML, html ); component.teardown(); }); } describe( 'formats', () => { before( setupHtmlEqual ); describe( 'amd', () => { it( 'generates an AMD module', () => { const source = deindent`