From e79e077b401f79f4bb609341e540532ffff4a5ec Mon Sep 17 00:00:00 2001 From: Pat Cavit Date: Wed, 16 May 2018 23:40:42 -0700 Subject: [PATCH 1/4] cross-platform test setup via shelljs My attempt at solving https://github.com/sveltejs/svelte/issues/1478 --- package.json | 1 + test/cli/index.js | 80 ++++++++++---------- test/cli/samples/basic/command.sh | 2 +- test/cli/samples/custom-element/command.sh | 2 +- test/cli/samples/dev/command.sh | 2 +- test/cli/samples/dir-sourcemap/command.sh | 2 +- test/cli/samples/dir-subdir/command.sh | 2 +- test/cli/samples/dir/command.sh | 2 +- test/cli/samples/globals/command.sh | 2 +- test/cli/samples/sourcemap-inline/command.sh | 2 +- test/cli/samples/sourcemap/command.sh | 2 +- test/cli/samples/ssr/command.sh | 2 +- test/cli/samples/store/command.sh | 2 +- 13 files changed, 51 insertions(+), 52 deletions(-) diff --git a/package.json b/package.json index 0e8cfe1880..36716012da 100644 --- a/package.json +++ b/package.json @@ -82,6 +82,7 @@ "rollup-watch": "^4.3.1", "sade": "^1.4.0", "sander": "^0.6.0", + "shelljs": "^0.8.2", "source-map": "0.6", "source-map-support": "^0.5.4", "tiny-glob": "^0.2.1", diff --git a/test/cli/index.js b/test/cli/index.js index 816bc3301e..ed29bb84d0 100644 --- a/test/cli/index.js +++ b/test/cli/index.js @@ -1,10 +1,10 @@ const fs = require('fs'); const path = require('path'); -const child_process = require('child_process'); const assert = require('assert'); const glob = require('tiny-glob/sync.js'); +const shell = require("shelljs"); -const bin = path.resolve(`svelte`); +const cli = path.resolve(__dirname, "../../cli/index.ts.js"); function normalize(str) { return str @@ -31,49 +31,47 @@ describe('cli', () => { const command = fs.readFileSync('command.sh', 'utf-8'); - child_process.exec(` - alias svelte=${bin} - mkdir -p actual - rm -rf actual/* - ${command} - `, (err, stdout, stderr) => { - if (err) { - done(err); - return; - } + shell.mkdir("-p", "actual"); + shell.rm("-rf", "actual/*"); + const { commandErr } = shell.exec(`node ${cli} ${command}`); + + if (commandErr) { + done(commandErr); + return; + } + + const actual = glob('**', { cwd: 'actual', filesOnly: true }) + .map(file => { + return { + file, + contents: normalize(fs.readFileSync(`actual/${file}`, 'utf-8')) + }; + }); - const actual = glob('**', { cwd: 'actual', filesOnly: true }) - .map(file => { - return { - file, - contents: normalize(fs.readFileSync(`actual/${file}`, 'utf-8')) - }; - }); - - const expected = glob('**', { cwd: 'expected', filesOnly: true }) - .map(file => { - return { - file, - contents: normalize( - fs.readFileSync(`expected/${file}`, 'utf-8') - ) - }; - }); - - actual.forEach((a, i) => { - const e = expected[i]; - - assert.equal(a.file, e.file, 'File list mismatch'); - - if (/\.map$/.test(a.file)) { - assert.deepEqual(JSON.parse(a.contents), JSON.parse(e.contents)); - } else { - assert.equal(a.contents, e.contents); - } + const expected = glob('**', { cwd: 'expected', filesOnly: true }) + .map(file => { + return { + file, + contents: normalize( + fs.readFileSync(`expected/${file}`, 'utf-8') + ) + }; }); - done(); + actual.forEach((a, i) => { + const e = expected[i]; + + assert.equal(a.file, e.file, 'File list mismatch'); + + if (/\.map$/.test(a.file)) { + assert.deepEqual(JSON.parse(a.contents), JSON.parse(e.contents)); + } else { + assert.equal(a.contents, e.contents); + } }); + + done(); + // }); }); }); }); diff --git a/test/cli/samples/basic/command.sh b/test/cli/samples/basic/command.sh index 0ae80e4c95..7a5e0e4892 100644 --- a/test/cli/samples/basic/command.sh +++ b/test/cli/samples/basic/command.sh @@ -1 +1 @@ -svelte compile src/Main.html > actual/Main.js +compile src/Main.html > actual/Main.js diff --git a/test/cli/samples/custom-element/command.sh b/test/cli/samples/custom-element/command.sh index b93c2cb16a..f638d82a80 100644 --- a/test/cli/samples/custom-element/command.sh +++ b/test/cli/samples/custom-element/command.sh @@ -1 +1 @@ -svelte compile src/Main.html --customElement > actual/Main.js +compile src/Main.html --customElement > actual/Main.js diff --git a/test/cli/samples/dev/command.sh b/test/cli/samples/dev/command.sh index 37d9b87fc0..aac44940ff 100644 --- a/test/cli/samples/dev/command.sh +++ b/test/cli/samples/dev/command.sh @@ -1 +1 @@ -svelte compile src/Main.html -d > actual/Main.js \ No newline at end of file +compile src/Main.html -d > actual/Main.js diff --git a/test/cli/samples/dir-sourcemap/command.sh b/test/cli/samples/dir-sourcemap/command.sh index 37089f3f44..f914d1d591 100644 --- a/test/cli/samples/dir-sourcemap/command.sh +++ b/test/cli/samples/dir-sourcemap/command.sh @@ -1 +1 @@ -svelte compile src -m -o actual \ No newline at end of file +compile src -m -o actual diff --git a/test/cli/samples/dir-subdir/command.sh b/test/cli/samples/dir-subdir/command.sh index 10067cb1f9..c767d236bb 100644 --- a/test/cli/samples/dir-subdir/command.sh +++ b/test/cli/samples/dir-subdir/command.sh @@ -1 +1 @@ -svelte compile src -o actual \ No newline at end of file +compile src -o actual diff --git a/test/cli/samples/dir/command.sh b/test/cli/samples/dir/command.sh index 10067cb1f9..c767d236bb 100644 --- a/test/cli/samples/dir/command.sh +++ b/test/cli/samples/dir/command.sh @@ -1 +1 @@ -svelte compile src -o actual \ No newline at end of file +compile src -o actual diff --git a/test/cli/samples/globals/command.sh b/test/cli/samples/globals/command.sh index 9ed0c2a844..a37e9f856a 100644 --- a/test/cli/samples/globals/command.sh +++ b/test/cli/samples/globals/command.sh @@ -1 +1 @@ -svelte compile src/Main.html -f iife -g the-answer:theAnswer > actual/Main.js \ No newline at end of file +compile src/Main.html -f iife -g the-answer:theAnswer > actual/Main.js diff --git a/test/cli/samples/sourcemap-inline/command.sh b/test/cli/samples/sourcemap-inline/command.sh index 36b5b71b8d..df0c2f9afe 100644 --- a/test/cli/samples/sourcemap-inline/command.sh +++ b/test/cli/samples/sourcemap-inline/command.sh @@ -1 +1 @@ -svelte compile src/Main.html -m inline -o actual/Main.js \ No newline at end of file +compile src/Main.html -m inline -o actual/Main.js diff --git a/test/cli/samples/sourcemap/command.sh b/test/cli/samples/sourcemap/command.sh index 4309d50b89..9e957c28fc 100644 --- a/test/cli/samples/sourcemap/command.sh +++ b/test/cli/samples/sourcemap/command.sh @@ -1 +1 @@ -svelte compile src/Main.html -m -o actual/Main.js \ No newline at end of file +compile src/Main.html -m -o actual/Main.js diff --git a/test/cli/samples/ssr/command.sh b/test/cli/samples/ssr/command.sh index 30e155691a..ae8bc695f1 100644 --- a/test/cli/samples/ssr/command.sh +++ b/test/cli/samples/ssr/command.sh @@ -1 +1 @@ -svelte compile --generate ssr src/Main.html > actual/Main.js +compile --generate ssr src/Main.html > actual/Main.js diff --git a/test/cli/samples/store/command.sh b/test/cli/samples/store/command.sh index a734fdc772..ec919719d5 100644 --- a/test/cli/samples/store/command.sh +++ b/test/cli/samples/store/command.sh @@ -1 +1 @@ -svelte compile src/Main.html --store > actual/Main.js +compile src/Main.html --store > actual/Main.js From bd1884a953ab35d28f753a8dfd393d937da7295f Mon Sep 17 00:00:00 2001 From: Conduitry Date: Thu, 17 May 2018 14:13:48 -0400 Subject: [PATCH 2/4] update yarn.lock --- yarn.lock | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/yarn.lock b/yarn.lock index 77ac332dfc..643395e6e6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1431,7 +1431,7 @@ glob@7.1.1: once "^1.3.0" path-is-absolute "^1.0.0" -glob@^7.0.3, glob@^7.0.5, glob@^7.0.6, glob@^7.1.2: +glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.0.6, glob@^7.1.2: version "7.1.2" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15" dependencies: @@ -1699,6 +1699,10 @@ inquirer@^3.0.6: strip-ansi "^4.0.0" through "^2.3.6" +interpret@^1.0.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.1.0.tgz#7ed1b1410c6a0e0f78cf95d3b8440c63f78b8614" + invariant@^2.2.2: version "2.2.4" resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6" @@ -2978,6 +2982,12 @@ readdirp@^2.0.0: readable-stream "^2.0.2" set-immediate-shim "^1.0.1" +rechoir@^0.6.2: + version "0.6.2" + resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384" + dependencies: + resolve "^1.1.6" + redent@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/redent/-/redent-1.0.0.tgz#cf916ab1fd5f1f16dfb20822dd6ec7f730c2afde" @@ -3329,6 +3339,14 @@ shebang-regex@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3" +shelljs@^0.8.2: + version "0.8.2" + resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.2.tgz#345b7df7763f4c2340d584abb532c5f752ca9e35" + dependencies: + glob "^7.0.0" + interpret "^1.0.0" + rechoir "^0.6.2" + signal-exit@^3.0.0, signal-exit@^3.0.1, signal-exit@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d" From 860a117f0eb60b048929b05bd8b639919899c739 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Thu, 17 May 2018 14:30:07 -0400 Subject: [PATCH 3/4] normalize paths in comments in cli tests --- test/cli/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/cli/index.js b/test/cli/index.js index ed29bb84d0..5ddb4eac10 100644 --- a/test/cli/index.js +++ b/test/cli/index.js @@ -9,7 +9,10 @@ const cli = path.resolve(__dirname, "../../cli/index.ts.js"); function normalize(str) { return str .replace(/^\s+$/gm, '') - .replace(/generated by Svelte v[.\d]+/, `generated by Svelte vx.y.z`) + .replace( + /\/\*(.*?)generated by Svelte v[.\d]+/, + (_, path) => `/*${path.replace(/\\/g, '/')}generated by Svelte vx.y.z` + ) .trim(); } From 5f156fd09c2aad62888080a0448def34671f76d0 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Thu, 17 May 2018 16:12:13 -0400 Subject: [PATCH 4/4] tidy, and revert changes to cli test sample commands --- test/cli/index.js | 5 +++-- test/cli/samples/basic/command.sh | 2 +- test/cli/samples/custom-element/command.sh | 2 +- test/cli/samples/dev/command.sh | 2 +- test/cli/samples/dir-sourcemap/command.sh | 2 +- test/cli/samples/dir-subdir/command.sh | 2 +- test/cli/samples/dir/command.sh | 2 +- test/cli/samples/globals/command.sh | 2 +- test/cli/samples/sourcemap-inline/command.sh | 2 +- test/cli/samples/sourcemap/command.sh | 2 +- test/cli/samples/ssr/command.sh | 2 +- test/cli/samples/store/command.sh | 2 +- 12 files changed, 14 insertions(+), 13 deletions(-) diff --git a/test/cli/index.js b/test/cli/index.js index 5ddb4eac10..bb17ec50c4 100644 --- a/test/cli/index.js +++ b/test/cli/index.js @@ -36,7 +36,9 @@ describe('cli', () => { shell.mkdir("-p", "actual"); shell.rm("-rf", "actual/*"); - const { commandErr } = shell.exec(`node ${cli} ${command}`); + const { commandErr } = shell.exec( + command.replace(/^svelte /, `node ${cli} `) + ); if (commandErr) { done(commandErr); @@ -74,7 +76,6 @@ describe('cli', () => { }); done(); - // }); }); }); }); diff --git a/test/cli/samples/basic/command.sh b/test/cli/samples/basic/command.sh index 7a5e0e4892..0ae80e4c95 100644 --- a/test/cli/samples/basic/command.sh +++ b/test/cli/samples/basic/command.sh @@ -1 +1 @@ -compile src/Main.html > actual/Main.js +svelte compile src/Main.html > actual/Main.js diff --git a/test/cli/samples/custom-element/command.sh b/test/cli/samples/custom-element/command.sh index f638d82a80..b93c2cb16a 100644 --- a/test/cli/samples/custom-element/command.sh +++ b/test/cli/samples/custom-element/command.sh @@ -1 +1 @@ -compile src/Main.html --customElement > actual/Main.js +svelte compile src/Main.html --customElement > actual/Main.js diff --git a/test/cli/samples/dev/command.sh b/test/cli/samples/dev/command.sh index aac44940ff..37d9b87fc0 100644 --- a/test/cli/samples/dev/command.sh +++ b/test/cli/samples/dev/command.sh @@ -1 +1 @@ -compile src/Main.html -d > actual/Main.js +svelte compile src/Main.html -d > actual/Main.js \ No newline at end of file diff --git a/test/cli/samples/dir-sourcemap/command.sh b/test/cli/samples/dir-sourcemap/command.sh index f914d1d591..37089f3f44 100644 --- a/test/cli/samples/dir-sourcemap/command.sh +++ b/test/cli/samples/dir-sourcemap/command.sh @@ -1 +1 @@ -compile src -m -o actual +svelte compile src -m -o actual \ No newline at end of file diff --git a/test/cli/samples/dir-subdir/command.sh b/test/cli/samples/dir-subdir/command.sh index c767d236bb..10067cb1f9 100644 --- a/test/cli/samples/dir-subdir/command.sh +++ b/test/cli/samples/dir-subdir/command.sh @@ -1 +1 @@ -compile src -o actual +svelte compile src -o actual \ No newline at end of file diff --git a/test/cli/samples/dir/command.sh b/test/cli/samples/dir/command.sh index c767d236bb..10067cb1f9 100644 --- a/test/cli/samples/dir/command.sh +++ b/test/cli/samples/dir/command.sh @@ -1 +1 @@ -compile src -o actual +svelte compile src -o actual \ No newline at end of file diff --git a/test/cli/samples/globals/command.sh b/test/cli/samples/globals/command.sh index a37e9f856a..9ed0c2a844 100644 --- a/test/cli/samples/globals/command.sh +++ b/test/cli/samples/globals/command.sh @@ -1 +1 @@ -compile src/Main.html -f iife -g the-answer:theAnswer > actual/Main.js +svelte compile src/Main.html -f iife -g the-answer:theAnswer > actual/Main.js \ No newline at end of file diff --git a/test/cli/samples/sourcemap-inline/command.sh b/test/cli/samples/sourcemap-inline/command.sh index df0c2f9afe..36b5b71b8d 100644 --- a/test/cli/samples/sourcemap-inline/command.sh +++ b/test/cli/samples/sourcemap-inline/command.sh @@ -1 +1 @@ -compile src/Main.html -m inline -o actual/Main.js +svelte compile src/Main.html -m inline -o actual/Main.js \ No newline at end of file diff --git a/test/cli/samples/sourcemap/command.sh b/test/cli/samples/sourcemap/command.sh index 9e957c28fc..4309d50b89 100644 --- a/test/cli/samples/sourcemap/command.sh +++ b/test/cli/samples/sourcemap/command.sh @@ -1 +1 @@ -compile src/Main.html -m -o actual/Main.js +svelte compile src/Main.html -m -o actual/Main.js \ No newline at end of file diff --git a/test/cli/samples/ssr/command.sh b/test/cli/samples/ssr/command.sh index ae8bc695f1..30e155691a 100644 --- a/test/cli/samples/ssr/command.sh +++ b/test/cli/samples/ssr/command.sh @@ -1 +1 @@ -compile --generate ssr src/Main.html > actual/Main.js +svelte compile --generate ssr src/Main.html > actual/Main.js diff --git a/test/cli/samples/store/command.sh b/test/cli/samples/store/command.sh index ec919719d5..a734fdc772 100644 --- a/test/cli/samples/store/command.sh +++ b/test/cli/samples/store/command.sh @@ -1 +1 @@ -compile src/Main.html --store > actual/Main.js +svelte compile src/Main.html --store > actual/Main.js