move tests around to facilitate registering babel based on environment

pull/353/head
Rich-Harris 8 years ago
parent 23b0f75af2
commit 60ed068a59

@ -2,4 +2,4 @@
--require reify
--recursive
./**/__test__.js
test/*.js
test/*/index.js

@ -1,4 +1 @@
--require reify
--recursive
./**/__test__.js
test/*.js
test/test.js

@ -44,9 +44,17 @@
},
"devDependencies": {
"acorn": "^4.0.4",
"babel": "^6.23.0",
"babel-core": "^6.23.1",
"babel-plugin-istanbul": "^3.0.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.18.0",
"babel-register": "^6.18.0",
"babel-plugin-transform-es2015-arrow-functions": "^6.22.0",
"babel-plugin-transform-es2015-block-scoping": "^6.23.0",
"babel-plugin-transform-es2015-destructuring": "^6.23.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.23.0",
"babel-plugin-transform-es2015-parameters": "^6.23.0",
"babel-plugin-transform-es2015-spread": "^6.22.0",
"babel-preset-env": "^1.2.1",
"babel-register": "^6.23.0",
"codecov": "^1.0.1",
"console-group": "^0.3.2",
"css-tree": "^1.0.0-alpha16",
@ -54,6 +62,7 @@
"eslint-plugin-import": "^2.2.0",
"estree-walker": "^0.3.0",
"fuzzyset.js": "0.0.1",
"glob": "^7.1.1",
"jsdom": "^9.9.1",
"locate-character": "^2.0.0",
"mocha": "^3.2.0",
@ -78,6 +87,11 @@
},
"babel": {
"plugins": [
"transform-es2015-arrow-functions",
"transform-es2015-block-scoping",
"transform-es2015-spread",
"transform-es2015-parameters",
"transform-es2015-destructuring",
"transform-es2015-modules-commonjs"
]
}

@ -1,6 +1,6 @@
import deindent from '../src/utils/deindent.js';
import deindent from '../../src/utils/deindent.js';
import assert from 'assert';
import { svelte, env, setupHtmlEqual } from './helpers.js';
import { svelte, env, setupHtmlEqual } from '../helpers.js';
function testAmd ( code, expectedId, dependencies, html ) {
const fn = new Function( 'define', code );

@ -1,10 +1,11 @@
import spaces from '../src/utils/spaces.js';
import spaces from '../../src/utils/spaces.js';
import assert from 'assert';
import * as path from 'path';
import * as fs from 'fs';
import * as acorn from 'acorn';
import * as babel from 'babel-core';
import { addLineNumbers, loadConfig, svelte, env, setupHtmlEqual } from './helpers.js';
import { addLineNumbers, loadConfig, svelte, env, setupHtmlEqual } from '../helpers.js';
let showCompiledCode = false;
let compileOptions = null;
@ -14,12 +15,18 @@ function getName ( filename ) {
return base[0].toUpperCase() + base.slice( 1 );
}
const nodeVersionMatch = /^v(\d)/.exec( process.version );
const legacy = +nodeVersionMatch[1] < 6;
const babelrc = require( '../../package.json' ).babel;
require.extensions[ '.html' ] = function ( module, filename ) {
const options = Object.assign({ filename, name: getName( filename ) }, compileOptions );
const { code } = svelte.compile( fs.readFileSync( filename, 'utf-8' ), options );
let { code } = svelte.compile( fs.readFileSync( filename, 'utf-8' ), options );
if ( showCompiledCode ) console.log( addLineNumbers( code ) ); // eslint-disable-line no-console
if ( legacy ) code = babel.transform( code, babelrc ).code;
return module._compile( code, filename );
};
@ -29,7 +36,7 @@ describe( 'generate', () => {
function runTest ( dir, shared ) {
if ( dir[0] === '.' ) return;
const config = loadConfig( `./generator/${dir}/_config.js` );
const config = loadConfig( `./generator/samples/${dir}/_config.js` );
if ( config.solo && process.env.CI ) {
throw new Error( 'Forgot to remove `solo: true` from test' );
@ -44,7 +51,7 @@ describe( 'generate', () => {
compileOptions.dev = config.dev;
try {
const source = fs.readFileSync( `test/generator/${dir}/main.html`, 'utf-8' );
const source = fs.readFileSync( `test/generator/samples/${dir}/main.html`, 'utf-8' );
compiled = svelte.compile( source, compileOptions );
} catch ( err ) {
if ( config.compileError ) {
@ -76,7 +83,7 @@ describe( 'generate', () => {
let SvelteComponent;
try {
SvelteComponent = require( `./generator/${dir}/main.html` ).default;
SvelteComponent = require( `./samples/${dir}/main.html` ).default;
} catch ( err ) {
if ( !config.show ) console.log( addLineNumbers( code ) ); // eslint-disable-line no-console
throw err;
@ -126,13 +133,13 @@ describe( 'generate', () => {
}
describe( 'inline helpers', () => {
fs.readdirSync( 'test/generator' ).forEach( dir => {
fs.readdirSync( 'test/generator/samples' ).forEach( dir => {
runTest( dir, null );
});
});
describe( 'shared helpers', () => {
fs.readdirSync( 'test/generator' ).forEach( dir => {
fs.readdirSync( 'test/generator/samples' ).forEach( dir => {
runTest( dir, path.resolve( 'shared.js' ) );
});
});

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save