Skip to content

Commit

Permalink
handle line ending differences in tests (sveltejs#4915)
Browse files Browse the repository at this point in the history
  • Loading branch information
pushkine authored and taylorzane committed Dec 17, 2020
1 parent 8e7cd8b commit e87e44e
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 24 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ jobs:
node-version: [8, 10, 12, 14]
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- run: git config --global core.autocrlf false
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ npm install

> Do not use Yarn to install the dependencies, as the specific package versions in `package-lock.json` are used to build and test Svelte.
> Many tests depend on newlines being preserved as `<LF>`. On Windows, you can ensure this by cloning with:
> ```bash
> git -c core.autocrlf=false clone https://github.com/sveltejs/svelte.git
> ```
To build the compiler, and all the other modules included in the package:

```bash
Expand Down
1 change: 1 addition & 0 deletions src/compiler/compile/utils/hash.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// https://github.com/darkskyapp/string-hash/blob/master/index.js
export default function hash(str: string): string {
str = str.replace(/\r/g, "");
let hash = 5381;
let i = str.length;

Expand Down
3 changes: 2 additions & 1 deletion test/css/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ describe('css', () => {
const config = try_require(`./samples/${dir}/_config.js`) || {};
const input = fs
.readFileSync(`${__dirname}/samples/${dir}/input.svelte`, 'utf-8')
.replace(/\s+$/, '');
.replace(/\s+$/, '')
.replace(/\r/g, '');

const expected_warnings = (config.warnings || []).map(normalize_warning);

Expand Down
4 changes: 2 additions & 2 deletions test/custom-elements/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('custom-elements', function() {
const warnings = [];

(solo ? it.only : skip ? it.skip : it)(dir, async () => {
const config = loadConfig(`./custom-elements/samples/${dir}/_config.js`);
const config = loadConfig(`${__dirname}/samples/${dir}/_config.js`);
const expected_warnings = config.warnings || [];

const bundle = await rollup({
Expand All @@ -82,7 +82,7 @@ describe('custom-elements', function() {

transform(code, id) {
if (id.endsWith('.svelte')) {
const compiled = svelte.compile(code, {
const compiled = svelte.compile(code.replace(/\r/g, ""), {
customElement: true,
dev: config.dev
});
Expand Down
6 changes: 3 additions & 3 deletions test/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("js", () => {
(solo ? it.only : it)(dir, () => {
const config = loadConfig(`${resolved}/_config.js`);

const input = fs.readFileSync(`${resolved}/input.svelte`, "utf-8").replace(/\s+$/, "");
const input = fs.readFileSync(`${resolved}/input.svelte`, "utf-8").replace(/\s+$/, "").replace(/\r/g, "");

let actual;

Expand Down Expand Up @@ -56,8 +56,8 @@ describe("js", () => {

try {
assert.equal(
actual.trim().replace(/^[ \t]+$/gm, ""),
expected.trim().replace(/^[ \t]+$/gm, "")
actual.trim().replace(/^[ \t]+$/gm, "").replace(/\r/g, ""),
expected.trim().replace(/^[ \t]+$/gm, "").replace(/\r/g, "")
);
} catch (error) {
if (shouldUpdateExpected()) {
Expand Down
10 changes: 3 additions & 7 deletions test/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('parse', () => {
(skip ? it.skip : solo ? it.only : it)(dir, () => {
const options = tryToLoadJson(`${__dirname}/samples/${dir}/options.json`) || {};

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

Expand All @@ -38,13 +38,9 @@ describe('parse', () => {
} catch (err) {
if (err.name !== 'ParseError') throw err;
if (!expectedError) throw err;

const { code, message, pos, start } = err
try {
assert.equal(err.code, expectedError.code);
assert.equal(err.message, expectedError.message);
assert.deepEqual(err.start, expectedError.start);
assert.equal(err.pos, expectedError.pos);
assert.equal(err.toString().split('\n')[0], `${expectedError.message} (${expectedError.start.line}:${expectedError.start.column})`);
assert.deepEqual({ code, message, pos, start }, expectedError);
} catch (err2) {
const e = err2.code === 'MODULE_NOT_FOUND' ? err : err2;
throw e;
Expand Down
4 changes: 2 additions & 2 deletions test/runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe("runtime", () => {
filename
}, compileOptions);

const { js: { code } } = compile(fs.readFileSync(filename, "utf-8"), options);
const { js: { code } } = compile(fs.readFileSync(filename, "utf-8").replace(/\r/g, ""), options);

return module._compile(code, filename);
};
Expand Down Expand Up @@ -103,7 +103,7 @@ describe("runtime", () => {

try {
const { js } = compile(
fs.readFileSync(`${cwd}/${file}`, 'utf-8'),
fs.readFileSync(`${cwd}/${file}`, 'utf-8').replace(/\r/g, ""),
{
...compileOptions,
filename: file
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 @@ -88,8 +88,8 @@ describe("ssr", () => {

try {
assert.equal(
css.code.replace(/^\s+/gm, ""),
expectedCss.replace(/^\s+/gm, "")
css.code.replace(/^\s+/gm, "").replace(/[\r\n]/g, ""),
expectedCss.replace(/^\s+/gm, "").replace(/[\r\n]/g, "")
);
} catch (error) {
if (shouldUpdateExpected()) {
Expand Down
2 changes: 1 addition & 1 deletion test/validator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("validate", () => {
(solo ? it.only : skip ? it.skip : it)(dir, () => {
const config = loadConfig(`${__dirname}/samples/${dir}/_config.js`);

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

0 comments on commit e87e44e

Please sign in to comment.