handle line ending differences in tests ()

pull/4925/head
pushkin 5 years ago committed by GitHub
parent 4124ec535e
commit 0da70f46b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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:

@ -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

@ -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;

@ -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);

@ -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({
@ -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
});

@ -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;
@ -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()) {

@ -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`);
@ -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;

@ -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);
};
@ -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

@ -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()) {

@ -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`);

Loading…
Cancel
Save