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