Skip to content

Commit

Permalink
allow solo for test suite (#3747)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau authored and Conduitry committed Oct 23, 2019
1 parent f68b3a3 commit 5dbb08d
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 48 deletions.
12 changes: 6 additions & 6 deletions test/css/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function create(code) {
}

describe('css', () => {
fs.readdirSync('test/css/samples').forEach(dir => {
fs.readdirSync(`${__dirname}/samples`).forEach(dir => {
if (dir[0] === '.') return;

// add .solo to a sample directory name to only run that test
Expand All @@ -51,7 +51,7 @@ describe('css', () => {
(solo ? it.only : skip ? it.skip : it)(dir, () => {
const config = try_require(`./samples/${dir}/_config.js`) || {};
const input = fs
.readFileSync(`test/css/samples/${dir}/input.svelte`, 'utf-8')
.readFileSync(`${__dirname}/samples/${dir}/input.svelte`, 'utf-8')
.replace(/\s+$/, '');

const expected_warnings = (config.warnings || []).map(normalize_warning);
Expand All @@ -74,10 +74,10 @@ describe('css', () => {
assert.deepEqual(dom_warnings, ssr_warnings);
assert.deepEqual(dom_warnings.map(normalize_warning), expected_warnings);

fs.writeFileSync(`test/css/samples/${dir}/_actual.css`, dom.css.code);
fs.writeFileSync(`${__dirname}/samples/${dir}/_actual.css`, dom.css.code);
const expected = {
html: read(`test/css/samples/${dir}/expected.html`),
css: read(`test/css/samples/${dir}/expected.css`)
html: read(`${__dirname}/samples/${dir}/expected.html`),
css: read(`${__dirname}/samples/${dir}/expected.css`)
};

assert.equal(dom.css.code.replace(/svelte(-ref)?-[a-z0-9]+/g, (m, $1) => $1 ? m : 'svelte-xyz'), expected.css);
Expand Down Expand Up @@ -112,7 +112,7 @@ describe('css', () => {
new ClientComponent({ target, props: config.props });
const html = target.innerHTML;

fs.writeFileSync(`test/css/samples/${dir}/_actual.html`, html);
fs.writeFileSync(`${__dirname}/samples/${dir}/_actual.html`, html);

assert.equal(
normalizeHtml(window, html.replace(/svelte(-ref)?-[a-z0-9]+/g, (m, $1) => $1 ? m : 'svelte-xyz')),
Expand Down
6 changes: 3 additions & 3 deletions test/custom-elements/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const page = `
</body>
`;

const assert = fs.readFileSync('test/custom-elements/assert.js', 'utf-8');
const assert = fs.readFileSync(`${__dirname}/assert.js`, 'utf-8');

describe('custom-elements', function() {
this.timeout(10000);
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('custom-elements', function() {
await browser.close();
});

fs.readdirSync('test/custom-elements/samples').forEach(dir => {
fs.readdirSync(`${__dirname}/samples`).forEach(dir => {
if (dir[0] === '.') return;

const solo = /\.solo$/.test(dir);
Expand All @@ -67,7 +67,7 @@ describe('custom-elements', function() {
const expected_warnings = config.warnings || [];

const bundle = await rollup({
input: `test/custom-elements/samples/${dir}/test.js`,
input: `${__dirname}/samples/${dir}/test.js`,
plugins: [
{
resolveId(importee) {
Expand Down
4 changes: 2 additions & 2 deletions test/hydration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('hydration', () => {
}

(config.skip ? it.skip : config.solo ? it.only : it)(dir, () => {
const cwd = path.resolve(`test/hydration/samples/${dir}`);
const cwd = path.resolve(`${__dirname}/samples/${dir}`);

compileOptions = config.compileOptions || {};

Expand Down Expand Up @@ -96,7 +96,7 @@ describe('hydration', () => {
});
}

fs.readdirSync('test/hydration/samples').forEach(dir => {
fs.readdirSync(`${__dirname}/samples`).forEach(dir => {
runTest(dir, null);
});
});
4 changes: 2 additions & 2 deletions test/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as path from "path";
import { loadConfig, svelte } from "../helpers.js";

describe("js", () => {
fs.readdirSync("test/js/samples").forEach(dir => {
fs.readdirSync(`${__dirname}/samples`).forEach(dir => {
if (dir[0] === ".") return;

// add .solo to a sample directory name to only run that test
Expand All @@ -15,7 +15,7 @@ describe("js", () => {
}

(solo ? it.only : it)(dir, () => {
dir = path.resolve("test/js/samples", dir);
dir = path.resolve(`${__dirname}/samples`, dir);
const config = loadConfig(`${dir}/_config.js`);

const input = fs.readFileSync(`${dir}/input.svelte`, "utf-8").replace(/\s+$/, "");
Expand Down
12 changes: 6 additions & 6 deletions test/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fs from 'fs';
import { svelte, tryToLoadJson } from '../helpers.js';

describe('parse', () => {
fs.readdirSync('test/parser/samples').forEach(dir => {
fs.readdirSync(`${__dirname}/samples`).forEach(dir => {
if (dir[0] === '.') return;

// add .solo to a sample directory name to only run that test
Expand All @@ -16,18 +16,18 @@ describe('parse', () => {
}

(solo ? it.only : it)(dir, () => {
const options = tryToLoadJson(`test/parser/samples/${dir}/options.json`) || {};
const options = tryToLoadJson(`${__dirname}/samples/${dir}/options.json`) || {};

const input = fs.readFileSync(`test/parser/samples/${dir}/input.svelte`, 'utf-8').replace(/\s+$/, '');
const expectedOutput = tryToLoadJson(`test/parser/samples/${dir}/output.json`);
const expectedError = tryToLoadJson(`test/parser/samples/${dir}/error.json`);
const input = fs.readFileSync(`${__dirname}/samples/${dir}/input.svelte`, 'utf-8').replace(/\s+$/, '');
const expectedOutput = tryToLoadJson(`${__dirname}/samples/${dir}/output.json`);
const expectedError = tryToLoadJson(`${__dirname}/samples/${dir}/error.json`);

try {
const { ast } = svelte.compile(input, Object.assign(options, {
generate: false
}));

fs.writeFileSync(`test/parser/samples/${dir}/_actual.json`, JSON.stringify(ast, null, '\t'));
fs.writeFileSync(`${__dirname}/samples/${dir}/_actual.json`, JSON.stringify(ast, null, '\t'));

assert.deepEqual(ast.html, expectedOutput.html);
assert.deepEqual(ast.css, expectedOutput.css);
Expand Down
10 changes: 5 additions & 5 deletions test/preprocess/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import * as assert from 'assert';
import { loadConfig, svelte } from '../helpers.js';

describe('preprocess', () => {
fs.readdirSync('test/preprocess/samples').forEach(dir => {
fs.readdirSync(`${__dirname}/samples`).forEach(dir => {
if (dir[0] === '.') return;

const config = loadConfig(`./preprocess/samples/${dir}/_config.js`);
const config = loadConfig(`${__dirname}/samples/${dir}/_config.js`);

if (config.solo && process.env.CI) {
throw new Error('Forgot to remove `solo: true` from test');
}

(config.skip ? it.skip : config.solo ? it.only : it)(dir, async () => {
const input = fs.readFileSync(`test/preprocess/samples/${dir}/input.svelte`, 'utf-8');
const expected = fs.readFileSync(`test/preprocess/samples/${dir}/output.svelte`, 'utf-8');
const input = fs.readFileSync(`${__dirname}/samples/${dir}/input.svelte`, 'utf-8');
const expected = fs.readFileSync(`${__dirname}/samples/${dir}/output.svelte`, 'utf-8');

const result = await svelte.preprocess(input, config.preprocess);
fs.writeFileSync(`test/preprocess/samples/${dir}/_actual.html`, result.code);
fs.writeFileSync(`${__dirname}/samples/${dir}/_actual.html`, result.code);

assert.equal(result.code, expected);

Expand Down
6 changes: 3 additions & 3 deletions test/runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe("runtime", () => {
function runTest(dir, hydrate) {
if (dir[0] === ".") return;

const config = loadConfig(`./runtime/samples/${dir}/_config.js`);
const config = loadConfig(`${__dirname}/samples/${dir}/_config.js`);

if (hydrate && config.skip_if_hydrate) return;

Expand All @@ -67,7 +67,7 @@ describe("runtime", () => {

compile = (config.preserveIdentifiers ? svelte : svelte$).compile;

const cwd = path.resolve(`test/runtime/samples/${dir}`);
const cwd = path.resolve(`${__dirname}/samples/${dir}`);

compileOptions = config.compileOptions || {};
compileOptions.format = 'cjs';
Expand Down Expand Up @@ -215,7 +215,7 @@ describe("runtime", () => {
});
}

fs.readdirSync("test/runtime/samples").forEach(dir => {
fs.readdirSync(`${__dirname}/samples`).forEach(dir => {
runTest(dir, false);
runTest(dir, true);
});
Expand Down
4 changes: 2 additions & 2 deletions test/server-side-rendering/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("ssr", () => {
return setupHtmlEqual();
});

fs.readdirSync("test/server-side-rendering/samples").forEach(dir => {
fs.readdirSync(`${__dirname}/samples`).forEach(dir => {
if (dir[0] === ".") return;

// add .solo to a sample directory name to only run that test, or
Expand All @@ -43,7 +43,7 @@ describe("ssr", () => {
}

(solo ? it.only : it)(dir, () => {
dir = path.resolve("test/server-side-rendering/samples", dir);
dir = path.resolve(`${__dirname}/samples`, dir);
try {
const Component = require(`${dir}/main.svelte`).default;

Expand Down
6 changes: 3 additions & 3 deletions test/sourcemaps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SourceMapConsumer } from "source-map";
import { getLocator } from "locate-character";

describe("sourcemaps", () => {
fs.readdirSync("test/sourcemaps/samples").forEach(dir => {
fs.readdirSync(`${__dirname}/samples`).forEach(dir => {
if (dir[0] === ".") return;

// add .solo to a sample directory name to only run that test
Expand All @@ -19,10 +19,10 @@ describe("sourcemaps", () => {

(solo ? it.only : skip ? it.skip : it)(dir, async () => {
const filename = path.resolve(
`test/sourcemaps/samples/${dir}/input.svelte`
`${__dirname}/samples/${dir}/input.svelte`
);
const outputFilename = path.resolve(
`test/sourcemaps/samples/${dir}/output`
`${__dirname}/samples/${dir}/output`
);

const input = fs.readFileSync(filename, "utf-8").replace(/\s+$/, "");
Expand Down
8 changes: 4 additions & 4 deletions test/stats/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as assert from 'assert';
import { svelte, loadConfig, tryToLoadJson } from '../helpers.js';

describe('stats', () => {
fs.readdirSync('test/stats/samples').forEach(dir => {
fs.readdirSync(`${__dirname}/samples`).forEach(dir => {
if (dir[0] === '.') return;

// add .solo to a sample directory name to only run that test
Expand All @@ -15,12 +15,12 @@ describe('stats', () => {
}

(solo ? it.only : skip ? it.skip : it)(dir, () => {
const config = loadConfig(`./stats/samples/${dir}/_config.js`);
const filename = `test/stats/samples/${dir}/input.svelte`;
const config = loadConfig(`${__dirname}/samples/${dir}/_config.js`);
const filename = `${__dirname}/samples/${dir}/input.svelte`;
const input = fs.readFileSync(filename, 'utf-8').replace(/\s+$/, '');

const expectedError = tryToLoadJson(
`test/stats/samples/${dir}/error.json`
`${__dirname}/samples/${dir}/error.json`
);

let result;
Expand Down
17 changes: 14 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ require('../internal');

console.clear();

glob('*/index.js', { cwd: 'test' }).forEach((file) => {
require('./' + file);
});
const testFolders = glob('*/index.js', { cwd: 'test' });
const solo = testFolders.find(folder => /\.solo/.test(folder));

if (solo) {
if (process.env.CI) {
throw new Error('Forgot to remove `solo: true` from test');
}
require('./' + solo);
} else {
testFolders.forEach(file => {
console.log('file', file);
require('./' + file);
});
}
10 changes: 5 additions & 5 deletions test/validator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as assert from "assert";
import { svelte, loadConfig, tryToLoadJson } from "../helpers.js";

describe("validate", () => {
fs.readdirSync("test/validator/samples").forEach(dir => {
fs.readdirSync(`${__dirname}/samples`).forEach(dir => {
if (dir[0] === ".") return;

// add .solo to a sample directory name to only run that test
Expand All @@ -15,11 +15,11 @@ describe("validate", () => {
}

(solo ? it.only : skip ? it.skip : it)(dir, () => {
const config = loadConfig(`./validator/samples/${dir}/_config.js`);
const config = loadConfig(`${__dirname}/samples/${dir}/_config.js`);

const input = fs.readFileSync(`test/validator/samples/${dir}/input.svelte`, "utf-8").replace(/\s+$/, "");
const expected_warnings = tryToLoadJson(`test/validator/samples/${dir}/warnings.json`) || [];
const expected_errors = tryToLoadJson(`test/validator/samples/${dir}/errors.json`);
const input = fs.readFileSync(`${__dirname}/samples/${dir}/input.svelte`, "utf-8").replace(/\s+$/, "");
const expected_warnings = tryToLoadJson(`${__dirname}/samples/${dir}/warnings.json`) || [];
const expected_errors = tryToLoadJson(`${__dirname}/samples/${dir}/errors.json`);

let error;

Expand Down
8 changes: 4 additions & 4 deletions test/vars/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as assert from 'assert';
import { svelte, loadConfig, tryToLoadJson } from '../helpers.js';

describe('vars', () => {
fs.readdirSync('test/vars/samples').forEach(dir => {
fs.readdirSync(`${__dirname}/samples`).forEach(dir => {
if (dir[0] === '.') return;

// add .solo to a sample directory name to only run that test
Expand All @@ -16,12 +16,12 @@ describe('vars', () => {

for (const generate of ['dom', 'ssr', false]) {
(solo ? it.only : skip ? it.skip : it)(`${dir}, generate: ${generate}`, () => {
const config = loadConfig(`./vars/samples/${dir}/_config.js`);
const filename = `test/vars/samples/${dir}/input.svelte`;
const config = loadConfig(`${__dirname}/samples/${dir}/_config.js`);
const filename = `${__dirname}/samples/${dir}/input.svelte`;
const input = fs.readFileSync(filename, 'utf-8').replace(/\s+$/, '');

const expectedError = tryToLoadJson(
`test/vars/samples/${dir}/error.json`
`${__dirname}/samples/${dir}/error.json`
);

let result;
Expand Down

0 comments on commit 5dbb08d

Please sign in to comment.