Skip to content

tests properly excluded on prepare #1778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ export class PlatformService implements IPlatformService {
let sourceFiles = this.$fs.enumerateFilesInDirectorySync(appSourceDirectoryPath, null, { includeEmptyDirectories: true });

if (this.$options.release) {
sourceFiles = sourceFiles.filter(source => source !== 'tests');
let testsFolderPath = path.join(appSourceDirectoryPath, 'tests');
sourceFiles = sourceFiles.filter(source => source.indexOf(testsFolderPath) === -1);
}

let hasTnsModulesInAppFolder = this.$fs.exists(path.join(appSourceDirectoryPath, constants.TNS_MODULES_FOLDER_NAME)).wait();
Expand Down
94 changes: 36 additions & 58 deletions test/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('Platform Service Tests', () => {

try {
platformService.addPlatforms(["android"]).wait();
} catch(err) {
} catch (err) {
assert.equal(errorMessage, err.message);
}
});
Expand All @@ -135,7 +135,7 @@ describe('Platform Service Tests', () => {

try {
platformService.addPlatforms(["ios"]).wait();
} catch(err) {
} catch (err) {
assert.equal(errorMessage, err.message);
}
});
Expand All @@ -154,7 +154,7 @@ describe('Platform Service Tests', () => {

try {
platformService.addPlatforms(["android"]).wait();
} catch(err) {
} catch (err) {
assert.equal(errorMessage, err.message);
}
});
Expand Down Expand Up @@ -196,6 +196,7 @@ describe('Platform Service Tests', () => {

describe("prepare platform unit tests", () => {
let fs: IFileSystem;

beforeEach(() => {
testInjector = createTestInjector();
testInjector.register("fs", fsLib.FileSystem);
Expand All @@ -208,6 +209,9 @@ describe('Platform Service Tests', () => {
let appFolderPath = path.join(tempFolder, "app");
fs.createDirectory(appFolderPath).wait();

let testsFolderPath = path.join(appFolderPath, "tests");
fs.createDirectory(testsFolderPath).wait();

let app1FolderPath = path.join(tempFolder, "app1");
fs.createDirectory(app1FolderPath).wait();

Expand All @@ -217,7 +221,7 @@ describe('Platform Service Tests', () => {
return { tempFolder, appFolderPath, app1FolderPath, appDestFolderPath, appResourcesFolderPath };
}

it("should process only files in app folder when preparing for iOS platform", () => {
function testPreparePlatform(platformToTest: string, release?: boolean) {
let { tempFolder, appFolderPath, app1FolderPath, appDestFolderPath, appResourcesFolderPath } = prepareDirStructure();

// Add platform specific files to app and app1 folders
Expand All @@ -240,7 +244,7 @@ describe('Platform Service Tests', () => {
return {
appDestinationDirectoryPath: appDestFolderPath,
appResourcesDestinationDirectoryPath: appResourcesFolderPath,
normalizedPlatformName: "iOS",
normalizedPlatformName: platformToTest,
platformProjectService: {
prepareProject: () => Future.fromResult(),
validate: () => Future.fromResult(),
Expand All @@ -259,69 +263,43 @@ describe('Platform Service Tests', () => {
projectData.projectDir = tempFolder;

platformService = testInjector.resolve("platformService");
platformService.preparePlatform("ios").wait();
let options : IOptions = testInjector.resolve("options");
options.release = release;
platformService.preparePlatform(platformToTest).wait();

let test1FileName = platformToTest.toLowerCase() === "ios" ? "test1.js" : "test2.js";
let test2FileName = platformToTest.toLowerCase() === "ios" ? "test2.js" : "test1.js";

// Asserts that the files in app folder are process as platform specific
assert.isTrue(fs.exists(path.join(appDestFolderPath, "app" , "test1.js")).wait());
assert.isTrue(fs.exists(path.join(appDestFolderPath, "app", test1FileName)).wait());
assert.isFalse(fs.exists(path.join(appDestFolderPath, "app", "test1-js")).wait());
assert.isFalse(fs.exists(path.join(appDestFolderPath, "app", "test2.js")).wait());

assert.isFalse(fs.exists(path.join(appDestFolderPath, "app", test2FileName)).wait());
assert.isFalse(fs.exists(path.join(appDestFolderPath, "app", "test2-js")).wait());

// Asserts that the files in app1 folder aren't process as platform specific
assert.isFalse(fs.exists(path.join(appDestFolderPath, "app1")).wait());
});
it("should process only files in app folder when preparing for Android platform", () => {
let { tempFolder, appFolderPath, app1FolderPath, appDestFolderPath, appResourcesFolderPath } = prepareDirStructure();
assert.isFalse(fs.exists(path.join(appDestFolderPath, "app1")).wait(), "Asserts that the files in app1 folder aren't process as platform specific");

// Add platform specific files to app and app1 folders
let platformSpecificFiles = [
"test1.ios.js", "test1-ios-js", "test2.android.js", "test2-android-js"
];

let destinationDirectories = [appFolderPath, app1FolderPath];

_.each(destinationDirectories, directoryPath => {
_.each(platformSpecificFiles, filePath => {
let fileFullPath = path.join(directoryPath, filePath);
fs.writeFile(fileFullPath, "testData").wait();
});
});

let platformsData = testInjector.resolve("platformsData");
platformsData.platformsNames = ["ios", "android"];
platformsData.getPlatformData = (platform: string) => {
return {
appDestinationDirectoryPath: appDestFolderPath,
appResourcesDestinationDirectoryPath: appResourcesFolderPath,
normalizedPlatformName: "Android",
platformProjectService: {
prepareProject: () => Future.fromResult(),
validate: () => Future.fromResult(),
createProject: (projectRoot: string, frameworkDir: string) => Future.fromResult(),
interpolateData: (projectRoot: string) => Future.fromResult(),
afterCreateProject: (projectRoot: string) => Future.fromResult(),
getAppResourcesDestinationDirectoryPath: () => Future.fromResult(""),
processConfigurationFilesFromAppResources: () => Future.fromResult(),
ensureConfigurationFileInAppResources: () => Future.fromResult(),
interpolateConfigurationFile: () => Future.fromResult()
}
};
};

let projectData = testInjector.resolve("projectData");
projectData.projectDir = tempFolder;
if (release) {
// Asserts that the files in tests folder aren't copied
assert.isFalse(fs.exists(path.join(appDestFolderPath, "tests")).wait(), "Asserts that the files in tests folder aren't copied");
}
}

platformService = testInjector.resolve("platformService");
platformService.preparePlatform("android").wait();
it("should process only files in app folder when preparing for iOS platform", () => {
testPreparePlatform("iOS");
});

// Asserts that the files in app folder are process as platform specific
assert.isTrue(fs.exists(path.join(appDestFolderPath, "app" , "test2.js")).wait());
assert.isFalse(fs.exists(path.join(appDestFolderPath, "app", "test2-js")).wait());
assert.isFalse(fs.exists(path.join(appDestFolderPath, "app", "test1.js")).wait());
assert.isFalse(fs.exists(path.join(appDestFolderPath, "app", "test1-js")).wait());
it("should process only files in app folder when preparing for Android platform", () => {
testPreparePlatform("Android");
});

it("should process only files in app folder when preparing for iOS platform", () => {
testPreparePlatform("iOS", true);
});

// Asserts that the files in app1 folder aren't process as platform specific
assert.isFalse(fs.exists(path.join(appDestFolderPath, "app1")).wait());
it("should process only files in app folder when preparing for Android platform", () => {
testPreparePlatform("Android", true);
});

it("invalid xml is caught", () => {
Expand Down