Skip to content

Commit

Permalink
Merge branch 'master' into gh-1489
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed May 24, 2018
2 parents b57be76 + 80077c1 commit df60585
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 43 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
86 changes: 44 additions & 42 deletions test/cli/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
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
.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();
}

Expand All @@ -31,49 +34,48 @@ 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(
command.replace(/^svelte /, `node ${cli} `)
);

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();
});
});
});
20 changes: 19 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit df60585

Please sign in to comment.