mirror of https://github.com/sveltejs/svelte
parent
fc7e6e6827
commit
f2f4a04ce1
@ -0,0 +1,40 @@
|
||||
{
|
||||
"root": true,
|
||||
"rules": {
|
||||
"indent": [ 2, "tab", { "SwitchCase": 1 } ],
|
||||
"semi": [ 2, "always" ],
|
||||
"keyword-spacing": [ 2, { "before": true, "after": true } ],
|
||||
"space-before-blocks": [ 2, "always" ],
|
||||
"space-before-function-paren": [ 2, "always" ],
|
||||
"no-mixed-spaces-and-tabs": [ 2, "smart-tabs" ],
|
||||
"no-cond-assign": 0,
|
||||
"no-unused-vars": 2,
|
||||
"object-shorthand": [ 2, "always" ],
|
||||
"no-const-assign": 2,
|
||||
"no-class-assign": 2,
|
||||
"no-this-before-super": 2,
|
||||
"no-var": 2,
|
||||
"no-unreachable": 2,
|
||||
"valid-typeof": 2,
|
||||
"quote-props": [ 2, "as-needed" ],
|
||||
"one-var": [ 2, "never" ],
|
||||
"prefer-arrow-callback": 2,
|
||||
"prefer-const": [ 2, { "destructuring": "all" } ],
|
||||
"arrow-spacing": 2
|
||||
},
|
||||
"env": {
|
||||
"es6": true,
|
||||
"browser": true,
|
||||
"node": true,
|
||||
"mocha": true
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:import/errors",
|
||||
"plugin:import/warnings"
|
||||
],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 6,
|
||||
"sourceType": "module"
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
export default function generate ( parsed ) {
|
||||
return `
|
||||
export default function createComponent ( options ) {
|
||||
console.log( 'TODO' );
|
||||
}
|
||||
`;
|
||||
}
|
@ -1,2 +1,9 @@
|
||||
export { default as parse } from './parse/index.js';
|
||||
export { default as generate } from './generate/index.js';
|
||||
import parse from './parse/index.js';
|
||||
import generate from './generate/index.js';
|
||||
|
||||
export function compile ( template ) {
|
||||
const parsed = parse( template );
|
||||
const generated = generate( parsed );
|
||||
|
||||
return generated;
|
||||
}
|
||||
|
@ -0,0 +1,4 @@
|
||||
export default {
|
||||
description: 'creates a factory with a single static element',
|
||||
html: '<span>test</span>'
|
||||
};
|
@ -0,0 +1 @@
|
||||
<span>test</span>
|
@ -0,0 +1,59 @@
|
||||
import { compile } from '../compiler/index.js';
|
||||
import * as assert from 'assert';
|
||||
import * as fs from 'fs';
|
||||
import jsdom from 'jsdom';
|
||||
|
||||
require.extensions[ '.svelte' ] = function ( module, filename ) {
|
||||
const source = fs.readFileSync( filename, 'utf-8' );
|
||||
const compiled = compile( source );
|
||||
|
||||
return module._compile( compiled, filename );
|
||||
};
|
||||
|
||||
describe( 'svelte', () => {
|
||||
function loadConfig ( dir ) {
|
||||
try {
|
||||
return require( `./samples/${dir}/_config.js` ).default;
|
||||
} catch ( err ) {
|
||||
if ( err.code === 'E_NOT_FOUND' ) {
|
||||
return {};
|
||||
}
|
||||
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
function env () {
|
||||
return new Promise( ( fulfil, reject ) => {
|
||||
jsdom.env( '<main></main>', ( err, window ) => {
|
||||
if ( err ) {
|
||||
reject( err );
|
||||
} else {
|
||||
fulfil( window );
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fs.readdirSync( 'test/samples' ).forEach( dir => {
|
||||
if ( dir[0] === '.' ) return;
|
||||
|
||||
it( dir, () => {
|
||||
const config = loadConfig( dir );
|
||||
const factory = require( `./samples/${dir}/main.svelte` ).default;
|
||||
|
||||
return env().then( window => {
|
||||
const target = window.document.querySelector( 'main' );
|
||||
|
||||
const component = factory({
|
||||
target,
|
||||
data: config.data
|
||||
});
|
||||
|
||||
if ( config.html ) {
|
||||
assert.equal( target.innerHTML, config.html );
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in new issue