Skip to content

Commit

Permalink
test: make unit tests windows compatible
Browse files Browse the repository at this point in the history
Due to somehow the correct 'cwd' is not set when initialising the yeoman generators most of the unit
tests fail because it can not locate the correct file to check. This commit changes this to
specifically store the working directory every time a new generator is created.

re #291
  • Loading branch information
AdmiringWorm committed Jul 22, 2020
1 parent 1973392 commit 9469ab1
Show file tree
Hide file tree
Showing 10 changed files with 592 additions and 285 deletions.
26 changes: 17 additions & 9 deletions __tests__/app/indexTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const skipDotnet = !sync("dotnet");

describe("generator:app", () => {
describe("default", () => {
let workDir = "";
beforeAll(() => {
return helpers
.run(generatorDir)
Expand All @@ -49,19 +50,21 @@ describe("generator:app", () => {
projectName: "MyTestApp",
})
)
.withOptions({ "start-year": "2018", "skip-dotnet": skipDotnet });
.withOptions({ "start-year": "2018", "skip-dotnet": skipDotnet })
.inTmpDir((dir) => (workDir = dir));
});

it("creates default project structure files", () => {
assert.file(expectedFiles);
assert.file(expectedFiles.map((v) => path.join(workDir, v)));
});

it("does not create contributing file when not enabled", () => {
assert.noFile("CONTRIBUTING.md");
assert.noFile(path.join(workDir, "CONTRIBUTING.md"));
});
});

describe("disable-travis", () => {
let workDir = "";
beforeAll(() => {
return helpers
.run(generatorDir)
Expand All @@ -70,15 +73,17 @@ describe("generator:app", () => {
enableTravis: false,
})
)
.withOptions({ "start-year": "2018", "skip-dotnet": skipDotnet });
.withOptions({ "start-year": "2018", "skip-dotnet": skipDotnet })
.inTmpDir((dir) => (workDir = dir));
});

it("does not create travis file when disabled", () => {
assert.noFile(".travis.yml");
assert.noFile(path.join(workDir, ".travis.yml"));
});
});

describe("enable-contributing", () => {
let workDir = "";
beforeAll(() => {
return helpers
.run(generatorDir)
Expand All @@ -87,15 +92,17 @@ describe("generator:app", () => {
enableContributing: true,
})
)
.withOptions({ "start-year": "2018", "skip-dotnet": skipDotnet });
.withOptions({ "start-year": "2018", "skip-dotnet": skipDotnet })
.inTmpDir((dir) => (workDir = dir));
});

it("creates contributing file when enabled", () => {
assert.file("CONTRIBUTING.md");
assert.file(path.join(workDir, "CONTRIBUTING.md"));
});
});

describe("disable-allcontributors", () => {
let workDir = "";
beforeAll(() => {
return helpers
.run(generatorDir)
Expand All @@ -104,11 +111,12 @@ describe("generator:app", () => {
enableAllContributors: false,
})
)
.withOptions({ "start-year": "2018", "skip-dotnet": skipDotnet });
.withOptions({ "start-year": "2018", "skip-dotnet": skipDotnet })
.inTmpDir((dir) => (workDir = dir));
});

it("should not create all contributors file when disabled", () => {
assert.noFile(".all-contributorsrc");
assert.noFile(path.join(workDir, ".all-contributorsrc"));
});
});
});
84 changes: 52 additions & 32 deletions __tests__/appveyor/indexTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ const baseDir = path.join(__dirname, "../../src/appveyor");

describe("generator:appveyor", () => {
describe("defaults", () => {
let workDir = "";
beforeEach(() => {
return helpers.run(baseDir).withPrompts(getPromptConfig());
return helpers
.run(baseDir)
.withPrompts(getPromptConfig())
.inTmpDir((dir) => (workDir = dir));
});

it("creates appveyor build file", () => {
assert.file([".appveyor.yml"]);
assert.file([path.join(workDir, ".appveyor.yml")]);
});

it("creates file with default content", () => {
assert.equalsFileContent(
".appveyor.yml",
path.join(workDir, ".appveyor.yml"),
fs.readFileSync(path.join(__dirname, "default.yml"), {
encoding: "utf8",
})
Expand All @@ -27,21 +31,25 @@ describe("generator:appveyor", () => {
});

describe("custom space", () => {
let workDir = "";
beforeEach(() => {
return helpers.run(baseDir).withPrompts(
getPromptConfig({
indentYamlSize: 4,
})
);
return helpers
.run(baseDir)
.withPrompts(
getPromptConfig({
indentYamlSize: 4,
})
)
.inTmpDir((dir) => (workDir = dir));
});

it("creates appveyor build file", () => {
assert.file([".appveyor.yml"]);
assert.file([path.join(workDir, ".appveyor.yml")]);
});

it("creates file with space indent set to 4", () => {
assert.equalsFileContent(
".appveyor.yml",
path.join(workDir, ".appveyor.yml"),
fs.readFileSync(path.join(__dirname, "custom_space.yml"), {
encoding: "utf8",
})
Expand All @@ -50,21 +58,25 @@ describe("generator:appveyor", () => {
});

describe("custom-cake", () => {
let workDir = "";
beforeEach(() => {
return helpers.run(baseDir).withPrompts(
getPromptConfig({
scriptName: "build.cake",
})
);
return helpers
.run(baseDir)
.withPrompts(
getPromptConfig({
scriptName: "build.cake",
})
)
.inTmpDir((dir) => (workDir = dir));
});

it("creates appveyor build file", () => {
assert.file([".appveyor.yml"]);
assert.file([path.join(workDir, ".appveyor.yml")]);
});

it("creates file with with custom cache", () => {
assert.equalsFileContent(
".appveyor.yml",
path.join(workDir, ".appveyor.yml"),
fs.readFileSync(path.join(__dirname, "custom_cake.yml"), {
encoding: "utf8",
})
Expand All @@ -73,21 +85,25 @@ describe("generator:appveyor", () => {
});

describe("with-linux", () => {
let workDir = "";
beforeEach(() => {
return helpers.run(baseDir).withPrompts(
getPromptConfig({
enableLinux: true,
})
);
return helpers
.run(baseDir)
.withPrompts(
getPromptConfig({
enableLinux: true,
})
)
.inTmpDir((dir) => (workDir = dir));
});

it("creates appveyor build file", () => {
assert.file([".appveyor.yml"]);
assert.file([path.join(workDir, ".appveyor.yml")]);
});

it("creates file with linux enabled", () => {
assert.equalsFileContent(
".appveyor.yml",
path.join(workDir, ".appveyor.yml"),
fs.readFileSync(path.join(__dirname, "linux_enabled.yml"), {
encoding: "utf8",
})
Expand All @@ -96,22 +112,26 @@ describe("generator:appveyor", () => {
});

describe("with-linux-and-custom-cake", () => {
let workDir = "";
beforeAll(() => {
return helpers.run(baseDir).withPrompts(
getPromptConfig({
enableLinux: true,
scriptName: "build.cake",
})
);
return helpers
.run(baseDir)
.withPrompts(
getPromptConfig({
enableLinux: true,
scriptName: "build.cake",
})
)
.inTmpDir((dir) => (workDir = dir));
});

it("creates appveyor build file", () => {
assert.file([".appveyor.yml"]);
assert.file([path.join(workDir, ".appveyor.yml")]);
});

it("creates file with linux enabled and custom cake cache", () => {
assert.equalsFileContent(
".appveyor.yml",
path.join(workDir, ".appveyor.yml"),
fs.readFileSync(path.join(__dirname, "linux_enabled_cake_custom.yml"), {
encoding: "utf8",
})
Expand Down
Loading

0 comments on commit 9469ab1

Please sign in to comment.