Skip to content

Commit

Permalink
[INTERNAL] Fixes windows tests
Browse files Browse the repository at this point in the history
Adjusts file paths to match the windows specific path separator
Compares json files in tests ignoring the newline character
  • Loading branch information
tobiasso85 authored and RandomByte committed Dec 18, 2018
1 parent e88ff9f commit 5664e8c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 60 deletions.
98 changes: 45 additions & 53 deletions test/lib/builder/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ const {test} = require("ava");
const path = require("path");
const chai = require("chai");
chai.use(require("chai-fs"));
const fs = require("graceful-fs");
const {promisify} = require("util");
const readFile = promisify(fs.readFile);
const assert = chai.assert;

const ui5Builder = require("../../../");
Expand All @@ -17,6 +20,8 @@ const libraryCore = path.join(__dirname, "..", "..", "fixtures", "sap.ui.core-ev

const recursive = require("recursive-readdir");

const newLineRegexp = /\r?\n|\r/g;

const findFiles = (folder) => {
return new Promise((resolve, reject) => {
recursive(folder, (err, files) => {
Expand All @@ -41,6 +46,20 @@ function cloneProjectTree(tree) {
return clone;
}

async function checkFileContentsIgnoreLineFeeds(expectedFiles, expectedPath, destPath) {
for (let i = 0; i < expectedFiles.length; i++) {
const expectedFile = expectedFiles[i];
const relativeFile = path.relative(expectedPath, expectedFile);
const destFile = path.join(destPath, relativeFile);
const currentFileContentPromise = readFile(destFile, "utf8");
const expectedFileContentPromise = readFile(expectedFile, "utf8");
const assertContents = ([currentContent, expectedContent]) => {
assert.equal(currentContent.replace(newLineRegexp, "\n"), expectedContent.replace(newLineRegexp, "\n"));
};
await Promise.all([currentFileContentPromise, expectedFileContentPromise]).then(assertContents);
}
}

test("Build application.a", (t) => {
const destPath = "./test/tmp/build/application.a/dest";
const expectedPath = path.join("test", "expected", "build", "application.a", "dest");
Expand All @@ -55,11 +74,8 @@ test("Build application.a", (t) => {
// Check for all directories and files
assert.directoryDeepEqual(destPath, expectedPath);
// Check for all file contents
expectedFiles.forEach((expectedFile) => {
const relativeFile = path.relative(expectedPath, expectedFile);
const destFile = path.join(destPath, relativeFile);
assert.fileEqual(destFile, expectedFile);
});
return checkFileContentsIgnoreLineFeeds(expectedFiles, expectedPath, destPath);
}).then(() => {
t.pass();
});
});
Expand All @@ -79,12 +95,9 @@ test("Build application.a [dev mode]", (t) => {
assert.directoryDeepEqual(destPath, expectedPath);

// Check for all file contents
expectedFiles.forEach((expectedFile) => {
const relativeFile = path.relative(expectedPath, expectedFile);
const destFile = path.join(destPath, relativeFile);
assert.fileEqual(destFile, expectedFile);
t.pass();
});
return checkFileContentsIgnoreLineFeeds(expectedFiles, expectedPath, destPath);
}).then(() => {
t.pass();
});
});

Expand All @@ -102,11 +115,8 @@ test("Build application.g", (t) => {
// Check for all directories and files
assert.directoryDeepEqual(destPath, expectedPath);
// Check for all file contents
expectedFiles.forEach((expectedFile) => {
const relativeFile = path.relative(expectedPath, expectedFile);
const destFile = path.join(destPath, relativeFile);
assert.fileEqual(destFile, expectedFile);
});
return checkFileContentsIgnoreLineFeeds(expectedFiles, expectedPath, destPath);
}).then(() => {
t.pass();
});
});
Expand All @@ -125,11 +135,8 @@ test("Build application.g with component preload paths", (t) => {
// Check for all directories and files
assert.directoryDeepEqual(destPath, expectedPath);
// Check for all file contents
expectedFiles.forEach((expectedFile) => {
const relativeFile = path.relative(expectedPath, expectedFile);
const destFile = path.join(destPath, relativeFile);
assert.fileEqual(destFile, expectedFile);
});
return checkFileContentsIgnoreLineFeeds(expectedFiles, expectedPath, destPath);
}).then(() => {
t.pass();
});
});
Expand All @@ -148,11 +155,8 @@ test("Build application.h", (t) => {
// Check for all directories and files
assert.directoryDeepEqual(destPath, expectedPath);
// Check for all file contents
expectedFiles.forEach((expectedFile) => {
const relativeFile = path.relative(expectedPath, expectedFile);
const destFile = path.join(destPath, relativeFile);
assert.fileEqual(destFile, expectedFile);
});
return checkFileContentsIgnoreLineFeeds(expectedFiles, expectedPath, destPath);
}).then(() => {
t.pass();
});
});
Expand All @@ -172,17 +176,14 @@ test("Build library.d with copyright from .library file", (t) => {
assert.directoryDeepEqual(destPath, expectedPath);

// Check for all file contents
expectedFiles.forEach((expectedFile) => {
const relativeFile = path.relative(expectedPath, expectedFile);
const destFile = path.join(destPath, relativeFile);
assert.fileEqual(destFile, expectedFile);
t.pass();
});
return checkFileContentsIgnoreLineFeeds(expectedFiles, expectedPath, destPath);
}).then(() => {
t.pass();
});
});

test("Build library.e with copyright from settings of ui5.yaml", (t) => {
const destPath = "./test/tmp/build/library.e/dest";
const destPath = path.join("test", "tmp", "build", "library.e", "dest");
const expectedPath = path.join("test", "expected", "build", "library.e", "dest");

return builder.build({
Expand All @@ -196,17 +197,14 @@ test("Build library.e with copyright from settings of ui5.yaml", (t) => {
assert.directoryDeepEqual(destPath, expectedPath);

// Check for all file contents
expectedFiles.forEach((expectedFile) => {
const relativeFile = path.relative(expectedPath, expectedFile);
const destFile = path.join(destPath, relativeFile);
assert.fileEqual(destFile, expectedFile);
t.pass();
});
return checkFileContentsIgnoreLineFeeds(expectedFiles, expectedPath, destPath);
}).then(() => {
t.pass();
});
});

test("Build library.h with custom bundles and component-preloads", (t) => {
const destPath = "./test/tmp/build/library.h/dest";
const destPath = path.join("test", "tmp", "build", "library.h", "dest");
const expectedPath = path.join("test", "expected", "build", "library.h", "dest");

return builder.build({
Expand All @@ -220,17 +218,14 @@ test("Build library.h with custom bundles and component-preloads", (t) => {
assert.directoryDeepEqual(destPath, expectedPath);

// Check for all file contents
expectedFiles.forEach((expectedFile) => {
const relativeFile = path.relative(expectedPath, expectedFile);
const destFile = path.join(destPath, relativeFile);
assert.fileEqual(destFile, expectedFile);
t.pass();
});
return checkFileContentsIgnoreLineFeeds(expectedFiles, expectedPath, destPath);
}).then(() => {
t.pass();
});
});

test("Build library.i with manifest info taken from .library and library.js", (t) => {
const destPath = "./test/tmp/build/library.i/dest";
const destPath = path.join("test", "tmp", "build", "library.i", "dest");
const expectedPath = path.join("test", "expected", "build", "library.i", "dest");

return builder.build({
Expand All @@ -244,12 +239,9 @@ test("Build library.i with manifest info taken from .library and library.js", (t
assert.directoryDeepEqual(destPath, expectedPath);

// Check for all file contents
expectedFiles.forEach((expectedFile) => {
const relativeFile = path.relative(expectedPath, expectedFile);
const destFile = path.join(destPath, relativeFile);
assert.fileEqual(destFile, expectedFile);
t.pass();
});
return checkFileContentsIgnoreLineFeeds(expectedFiles, expectedPath, destPath);
}).then(() => {
t.pass();
});
});

Expand Down
12 changes: 6 additions & 6 deletions test/lib/lbt/analyzer/ComponentAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test("routing with routes as array", (t) => {
};

const subject = new ComponentAnalyzer(mockPool);
return subject.analyze({name: "test/Component.js"}, mockInfo);
return subject.analyze({name: path.join("test", "Component.js")}, mockInfo);
});


Expand Down Expand Up @@ -82,7 +82,7 @@ test("routing with routes as object", (t) => {
};

const subject = new ComponentAnalyzer(mockPool);
return subject.analyze({name: "test/Component.js"}, mockInfo);
return subject.analyze({name: path.join("test", "Component.js")}, mockInfo);
});

test("routing with route with multiple targets", (t) => {
Expand Down Expand Up @@ -116,7 +116,7 @@ test("routing with route with multiple targets", (t) => {
};

const subject = new ComponentAnalyzer(mockPool);
return subject.analyze({name: "test/Component.js"}, mockInfo).then( () => {
return subject.analyze({name: path.join("test", "Component.js")}, mockInfo).then( () => {
t.deepEqual(mockInfo.deps, [
"test/view/Master.view.xml",
"test/view/Detail.view.xml"
Expand Down Expand Up @@ -164,7 +164,7 @@ test("routing with targets with local config", (t) => {
};

const subject = new ComponentAnalyzer(mockPool);
return subject.analyze({name: "test/Component.js"}, mockInfo).then( () => {
return subject.analyze({name: path.join("test", "Component.js")}, mockInfo).then( () => {
t.deepEqual(mockInfo.deps, [
"test/view/Master.view.js",
"test/subview/Detail.view.xml"
Expand Down Expand Up @@ -193,7 +193,7 @@ test("rootView with object", (t) => {
};

const subject = new ComponentAnalyzer(mockPool);
return subject.analyze({name: "test/Component.js"}, mockInfo).then( () => {
return subject.analyze({name: path.join("test", "Component.js")}, mockInfo).then( () => {
t.deepEqual(mockInfo.deps, [
"test/view/App.view.js",
], "dependencies should be correct");
Expand All @@ -217,7 +217,7 @@ test("rootView with string", (t) => {
};

const subject = new ComponentAnalyzer(mockPool);
return subject.analyze({name: "test/Component.js"}, mockInfo).then( () => {
return subject.analyze({name: path.join("test", "Component.js")}, mockInfo).then( () => {
t.deepEqual(mockInfo.deps, [
"test/view/App.view.xml",
], "dependencies should be correct");
Expand Down
2 changes: 1 addition & 1 deletion test/lib/tasks/bundlers/generateManifestBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const findFiles = (folder) => {
test("Build application.b with manifestBundler", (t) => {
const destPath = "./test/tmp/build/application.b/dest";
const destBundle = destPath + "/manifest-bundle";
const expectedPath = "./test/expected/build/application.b/dest";
const expectedPath = path.join("test", "expected", "build", "application.b", "dest");
const excludedTasks = ["*"];
const includedTasks = ["generateManifestBundle"];

Expand Down

0 comments on commit 5664e8c

Please sign in to comment.