rig tests up

pull/31/head
Rich Harris 8 years ago
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'; import parse from './parse/index.js';
export { default as generate } from './generate/index.js'; import generate from './generate/index.js';
export function compile ( template ) {
const parsed = parse( template );
const generated = generate( parsed );
return generated;
}

@ -4,7 +4,8 @@
"description": "The frameworkless UI framework", "description": "The frameworkless UI framework",
"main": "dist/svelte-compiler.js", "main": "dist/svelte-compiler.js",
"scripts": { "scripts": {
"test": "mocha --opts mocha.opts --recursive ./**/__test__.js" "test": "mocha --opts mocha.opts --recursive ./**/__test__.js test/test.js",
"lint": "eslint compiler"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -23,6 +24,9 @@
}, },
"homepage": "https://gitlab.com/Rich-Harris/svelte#README", "homepage": "https://gitlab.com/Rich-Harris/svelte#README",
"devDependencies": { "devDependencies": {
"eslint": "^3.10.2",
"eslint-plugin-import": "^2.2.0",
"jsdom": "^9.8.3",
"mocha": "^3.1.2", "mocha": "^3.1.2",
"reify": "^0.4.0" "reify": "^0.4.0"
}, },

@ -0,0 +1,4 @@
export default {
description: 'creates a factory with a single static element',
html: '<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…
Cancel
Save