diff --git a/.gitattributes b/.gitattributes index 391f0a4e4..6313b56c5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1 @@ -* text=auto -*.js text eol=lf +* text=auto eol=lf diff --git a/.travis.yml b/.travis.yml index 5844785d4..023f03edb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,24 @@ language: node_js # don't install any environment node_js: -- "8" -- "10" +- "node" + +os: +- linux +- osx +- windows + +matrix: + include: + - os: linux + node_js: + - "10" + - os: linux + node_js: + - "8" after_script: -- npm run report-coveralls +- if [[ "$TRAVIS_OS_NAME" == 'linux' ]]; then npm run report-coveralls; fi notifications: webhooks: https://coveralls.io/webhook diff --git a/test/lib/builder/builder.js b/test/lib/builder/builder.js index 9cc5a4c09..1341722b2 100644 --- a/test/lib/builder/builder.js +++ b/test/lib/builder/builder.js @@ -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("../../../"); @@ -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) => { @@ -41,9 +46,23 @@ 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 = "./test/expected/build/application.a/dest"; + const expectedPath = path.join("test", "expected", "build", "application.a", "dest"); return builder.build({ tree: applicationATree, @@ -55,18 +74,15 @@ 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(); }); }); test("Build application.a [dev mode]", (t) => { const destPath = "./test/tmp/build/application.a/dest-dev"; - const expectedPath = "./test/expected/build/application.a/dest-dev"; + const expectedPath = path.join("test", "expected", "build", "application.a", "dest-dev"); return builder.build({ tree: applicationATree, @@ -79,18 +95,15 @@ 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(); }); }); test("Build application.g", (t) => { const destPath = "./test/tmp/build/application.g/dest"; - const expectedPath = "./test/expected/build/application.g/dest"; + const expectedPath = path.join("test", "expected", "build", "application.g", "dest"); return builder.build({ tree: applicationGTree, @@ -102,18 +115,15 @@ 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(); }); }); test("Build application.g with component preload paths", (t) => { const destPath = "./test/tmp/build/application.g/dest2"; - const expectedPath = "./test/expected/build/application.g/dest"; + const expectedPath = path.join("test", "expected", "build", "application.g", "dest"); return builder.build({ tree: applicationGTreeComponentPreloadPaths, @@ -125,18 +135,15 @@ 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(); }); }); test("Build application.h", (t) => { const destPath = "./test/tmp/build/application.h/dest"; - const expectedPath = "./test/expected/build/application.h/dest"; + const expectedPath = path.join("test", "expected", "build", "application.h", "dest"); return builder.build({ tree: applicationHTree, @@ -148,18 +155,15 @@ 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(); }); }); test("Build library.d with copyright from .library file", (t) => { const destPath = "./test/tmp/build/library.d/dest"; - const expectedPath = "./test/expected/build/library.d/dest"; + const expectedPath = path.join("test", "expected", "build", "library.d", "dest"); return builder.build({ tree: libraryDTree, @@ -172,18 +176,15 @@ 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 expectedPath = "./test/expected/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({ tree: libraryETree, @@ -196,18 +197,15 @@ 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 expectedPath = "./test/expected/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({ tree: libraryHTree, @@ -220,18 +218,15 @@ 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 expectedPath = "./test/expected/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({ tree: libraryITree, @@ -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(); }); }); diff --git a/test/lib/lbt/analyzer/ComponentAnalyzer.js b/test/lib/lbt/analyzer/ComponentAnalyzer.js index 2400634b6..660e82f8d 100644 --- a/test/lib/lbt/analyzer/ComponentAnalyzer.js +++ b/test/lib/lbt/analyzer/ComponentAnalyzer.js @@ -1,10 +1,10 @@ const {test} = require("ava"); -const Path = require("path"); +const path = require("path"); const ComponentAnalyzer = require("../../../../lib/lbt/analyzer/ComponentAnalyzer"); -function createMockPool(path, manifest) { - const expectedPath = Path.join(path, "manifest.json"); +function createMockPool(relPath, manifest) { + const expectedPath = path.join(relPath, "manifest.json"); return { async findResource(name) { if (name !== expectedPath) { @@ -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); }); @@ -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) => { @@ -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" @@ -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" @@ -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"); @@ -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"); diff --git a/test/lib/tasks/bundlers/generateManifestBundle.js b/test/lib/tasks/bundlers/generateManifestBundle.js index 4d7fa56f4..d015cce7c 100644 --- a/test/lib/tasks/bundlers/generateManifestBundle.js +++ b/test/lib/tasks/bundlers/generateManifestBundle.js @@ -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"];