diff --git a/__tests__/app/indexTests.ts b/__tests__/app/indexTests.ts index cead61d0..021a6f50 100644 --- a/__tests__/app/indexTests.ts +++ b/__tests__/app/indexTests.ts @@ -38,6 +38,7 @@ const skipDotnet = !sync("dotnet"); describe("generator:app", () => { describe("default", () => { + let workDir = ""; beforeAll(() => { return helpers .run(generatorDir) @@ -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) @@ -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) @@ -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) @@ -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")); }); }); }); diff --git a/__tests__/appveyor/indexTests.ts b/__tests__/appveyor/indexTests.ts index 0088d827..6d24d323 100644 --- a/__tests__/appveyor/indexTests.ts +++ b/__tests__/appveyor/indexTests.ts @@ -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", }) @@ -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", }) @@ -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", }) @@ -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", }) @@ -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", }) diff --git a/__tests__/build/indexTests.ts b/__tests__/build/indexTests.ts index c14421a2..7ed03e09 100644 --- a/__tests__/build/indexTests.ts +++ b/__tests__/build/indexTests.ts @@ -40,113 +40,157 @@ function assertFileContent(filePath: string, expectedFile: string) { describe("generator:travis", () => { describe("default", () => { + let workDir = ""; beforeAll(() => { - return helpers.run(generatorDir).withPrompts(getPromptConfig()); + return helpers + .run(generatorDir) + .withPrompts(getPromptConfig()) + .inTmpDir((dir) => (workDir = dir)); }); it("creates default project structure files", () => { - assert.file(expectedFiles); + assert.file(expectedFiles.map((v) => path.join(workDir, v))); }); for (const fileCheck of expectedContentFiles) { it(`creates ${fileCheck.name} file with expected content`, () => { assertFileContent( - fileCheck.testFile, + path.join(workDir, fileCheck.testFile), "default/" + fileCheck.expectedFile ); }); } it("windows bootstrapper sets cake build file to expected script name", () => { - assert.fileContent("build.ps1", /\$Script\s*=\s*"recipe\.cake"/); + assert.fileContent( + path.join(workDir, "build.ps1"), + /\$Script\s*=\s*"recipe\.cake"/ + ); }); }); describe("custom prompts", () => { + let workDir = ""; beforeAll(() => { - return helpers.run(generatorDir).withPrompts( - getPromptConfig({ - projectName: "MyAddin", - repositoryOwner: "gep13", - scriptName: "setup.cake", - sourceDir: "./source", - }) - ); + return helpers + .run(generatorDir) + .withPrompts( + getPromptConfig({ + projectName: "MyAddin", + repositoryOwner: "gep13", + scriptName: "setup.cake", + sourceDir: "./source", + }) + ) + .inTmpDir((dir) => (workDir = dir)); }); it("creates build files", () => { - assert.file([ - "build.ps1", - "build.sh", - "setup.cake", - "tools/packages.config", - ]); + assert.file( + [ + "build.ps1", + "build.sh", + "setup.cake", + "tools/packages.config", + ].map((v) => path.join(workDir, v)) + ); }); it("Unix bootstrapper should set cake script name", () => { - assert.fileContent("build.sh", /SCRIPT="setup\.cake"/); + assert.fileContent( + path.join(workDir, "build.sh"), + /SCRIPT="setup\.cake"/ + ); }); it("Windows bootstrapper should set cake script name", () => { - assert.fileContent("build.ps1", /\$Script\s*=\s*"setup\.cake"/); + assert.fileContent( + path.join(workDir, "build.ps1"), + /\$Script\s*=\s*"setup\.cake"/ + ); }); it("Cake script should set project name", () => { - assert.fileContent("setup.cake", /title:\s*"Cake\.MyAddin"/); - assert.fileContent("setup.cake", /repositoryName:\s*"Cake\.MyAddin"/); + assert.fileContent( + path.join(workDir, "setup.cake"), + /title:\s*"Cake\.MyAddin"/ + ); + assert.fileContent( + path.join(workDir, "setup.cake"), + /repositoryName:\s*"Cake\.MyAddin"/ + ); }); it("Cake script should set repositoryOwner", () => { - assert.fileContent("setup.cake", /repositoryOwner:\s*"gep13"/); + assert.fileContent( + path.join(workDir, "setup.cake"), + /repositoryOwner:\s*"gep13"/ + ); }); it("Cake script should set source directory", () => { - assert.fileContent("setup.cake", /sourceDirectoryPath:\s*"\.\/source"/); + assert.fileContent( + path.join(workDir, "setup.cake"), + /sourceDirectoryPath:\s*"\.\/source"/ + ); }); }); describe("custom handling for cake-contrib", () => { + let workDir = ""; beforeAll(() => { - return helpers.run(generatorDir).withPrompts( - getPromptConfig({ - projectName: "MyContribAddin", - repositoryOwner: "cake-contrib", - }) - ); + return helpers + .run(generatorDir) + .withPrompts( + getPromptConfig({ + projectName: "MyContribAddin", + repositoryOwner: "cake-contrib", + }) + ) + .inTmpDir((dir) => (workDir = dir)); }); it("creates build files", () => { - assert.file([ - "build.ps1", - "build.sh", - "recipe.cake", - "tools/packages.config", - ]); + assert.file( + [ + "build.ps1", + "build.sh", + "recipe.cake", + "tools/packages.config", + ].map((v) => path.join(workDir, v)) + ); }); it("Cake script should set source directory", () => { - assert.fileContent("recipe.cake", /appVeyorAccountName:\s*"cakecontrib"/); + assert.fileContent( + path.join(workDir, "recipe.cake"), + /appVeyorAccountName:\s*"cakecontrib"/ + ); }); }); describe("indentation", () => { + let workDir = ""; describe("space", () => { beforeAll(() => { - return helpers.run(generatorDir).withPrompts( - getPromptConfig({ - indentSize: 2, - }) - ); + return helpers + .run(generatorDir) + .withPrompts( + getPromptConfig({ + indentSize: 2, + }) + ) + .inTmpDir((dir) => (workDir = dir)); }); it("creates default project structure files", () => { - assert.file(expectedFiles); + assert.file(expectedFiles.map((v) => path.join(workDir, v))); }); for (const fileCheck of expectedContentFiles) { it(`creates ${fileCheck.name} file with expected content`, () => { assertFileContent( - fileCheck.testFile, + path.join(workDir, fileCheck.testFile), "space/" + fileCheck.expectedFile ); }); @@ -154,22 +198,26 @@ describe("generator:travis", () => { }); describe("tabs", () => { + let workDir2 = ""; beforeAll(() => { - return helpers.run(generatorDir).withPrompts( - getPromptConfig({ - useTabs: true, - }) - ); + return helpers + .run(generatorDir) + .withPrompts( + getPromptConfig({ + useTabs: true, + }) + ) + .inTmpDir((dir) => (workDir2 = dir)); }); it("creates default project structure files", () => { - assert.file(expectedFiles); + assert.file(expectedFiles.map((v) => path.join(workDir2, v))); }); for (const fileCheck of expectedContentFiles) { it(`creates ${fileCheck.name} file with tabs instead of spaces`, () => { assertFileContent( - fileCheck.testFile, + path.join(workDir2, fileCheck.testFile), "tabs/" + fileCheck.expectedFile ); }); diff --git a/__tests__/conduct/indexTests.ts b/__tests__/conduct/indexTests.ts index 47fd74c5..e112136d 100644 --- a/__tests__/conduct/indexTests.ts +++ b/__tests__/conduct/indexTests.ts @@ -4,17 +4,22 @@ import * as helpers from "yeoman-test"; import { getPromptConfig } from "../../defaultConfigs"; describe("generator:conduct", () => { + let workDir = ""; beforeAll(() => helpers .run(join(__dirname, "../../src/conduct")) .withPrompts(getPromptConfig({ emailAddress: "kim.nordmo@gmail.com" })) + .inTmpDir((dir) => (workDir = dir)) ); it("should create file", () => { - assert.file("CODE_OF_CONDUCT.md"); + assert.file(join(workDir, "CODE_OF_CONDUCT.md")); }); it("should replace email address", () => { - assert.fileContent("CODE_OF_CONDUCT.md", /kim\.nordmo@gmail.com/); + assert.fileContent( + join(workDir, "CODE_OF_CONDUCT.md"), + /kim\.nordmo@gmail.com/ + ); }); }); diff --git a/__tests__/config/indexTests.ts b/__tests__/config/indexTests.ts index 6bfedd47..9c1b78b7 100644 --- a/__tests__/config/indexTests.ts +++ b/__tests__/config/indexTests.ts @@ -8,21 +8,24 @@ const generatorDir = join(__dirname, "../../src/config"); describe("generator:config", () => { describe("default", () => { + let workDir = ""; beforeAll(() => - run(generatorDir).withOptions( - getPromptConfig({ - enableAllContributors: true, - }) - ) + run(generatorDir) + .withOptions( + getPromptConfig({ + enableAllContributors: true, + }) + ) + .inTmpDir((dir) => (workDir = dir)) ); it("creates editorconfig file", () => { - assert.file(".editorconfig"); + assert.file(join(workDir, ".editorconfig")); }); it("creates editorconfig with expected content", () => { assert.equalsFileContent( - ".editorconfig", + join(workDir, ".editorconfig"), readFileSync(join(__dirname, "expected/.editorconfig"), { encoding: "utf8", }) @@ -30,12 +33,12 @@ describe("generator:config", () => { }); it("creates gitattributes file", () => { - assert.file(".gitattributes"); + assert.file(join(workDir, ".gitattributes")); }); it("creates gitattributes with expected content", () => { assert.equalsFileContent( - ".gitattributes", + join(workDir, ".gitattributes"), readFileSync(join(__dirname, "expected/.gitattributes"), { encoding: "utf8", }) @@ -43,12 +46,12 @@ describe("generator:config", () => { }); it("creates gitignore file", () => { - assert.file(".gitignore"); + assert.file(join(workDir, ".gitignore")); }); it("creates gitignore with expected content", () => { assert.equalsFileContent( - ".gitignore", + join(workDir, ".gitignore"), readFileSync(join(__dirname, "expected/.gitignore"), { encoding: "utf8", }) @@ -56,12 +59,12 @@ describe("generator:config", () => { }); it("creates GitReleaseManager file", () => { - assert.file("GitReleaseManager.yaml"); + assert.file(join(workDir, "GitReleaseManager.yaml")); }); it("creates GitReleaseManager with expected content", () => { assert.equalsFileContent( - "GitReleaseManager.yaml", + join(workDir, "GitReleaseManager.yaml"), readFileSync(join(__dirname, "expected/GitReleaseManager.yaml"), { encoding: "utf8", }) @@ -69,12 +72,12 @@ describe("generator:config", () => { }); it("creates all-contributorsrc file", () => { - assert.file(".all-contributorsrc"); + assert.file(join(workDir, ".all-contributorsrc")); }); it("creates all-contributorsrc with expected content", () => { assert.equalsFileContent( - ".all-contributorsrc", + join(workDir, ".all-contributorsrc"), readFileSync(join(__dirname, "expected/.all-contributorsrc"), { encoding: "utf8", }) @@ -83,27 +86,35 @@ describe("generator:config", () => { }); describe("disable all-contributors", () => { - beforeAll(() => run(generatorDir).withPrompts(getPromptConfig())); + let workDir = ""; + beforeAll(() => + run(generatorDir) + .withPrompts(getPromptConfig()) + .inTmpDir((dir) => (workDir = dir)) + ); it("should not create all contributors configuratior file", () => { - assert.noFile(".all-contributorsrc"); + assert.noFile(join(workDir, ".all-contributorsrc")); }); }); describe("indentation", () => { describe("tabs", () => { + let workDir = ""; beforeAll(() => - run(generatorDir).withPrompts( - getPromptConfig({ - enableAllContributors: true, - useTabs: true, - }) - ) + run(generatorDir) + .withPrompts( + getPromptConfig({ + enableAllContributors: true, + useTabs: true, + }) + ) + .inTmpDir((dir) => (workDir = dir)) ); it("should create editorconfig with default to tabs", () => { const re = /\[\*\][^\[]*indent_style\s=\stab\s/g; - const buffer = readFileSync(".editorconfig", { + const buffer = readFileSync(join(workDir, ".editorconfig"), { encoding: "utf-8", }); @@ -114,7 +125,7 @@ describe("generator:config", () => { it("should create editorconfig with yaml to space", () => { const re = /\[\*\.{yml,yaml}\][^\[]*indent_style\s=\sspace\s/g; - const buffer = readFileSync(".editorconfig", { + const buffer = readFileSync(join(workDir, ".editorconfig"), { encoding: "utf-8", }); @@ -125,18 +136,21 @@ describe("generator:config", () => { }); describe("default-space-set-to-2", () => { + let workDir = ""; beforeAll(() => - run(generatorDir).withPrompts( - getPromptConfig({ - enableAllContributors: true, - indentSize: 2, - }) - ) + run(generatorDir) + .withPrompts( + getPromptConfig({ + enableAllContributors: true, + indentSize: 2, + }) + ) + .inTmpDir((dir) => (workDir = dir)) ); it("creates all-contributorsrc with expected content", () => { assert.equalsFileContent( - ".all-contributorsrc", + join(workDir, ".all-contributorsrc"), readFileSync(join(__dirname, "expected/space/.all-contributorsrc"), { encoding: "utf8", }) @@ -145,7 +159,7 @@ describe("generator:config", () => { it("creates .editorconfig with expected content", () => { assert.equalsFileContent( - ".editorconfig", + join(workDir, ".editorconfig"), readFileSync(join(__dirname, "expected/space/.editorconfig"), { encoding: "utf8", }) @@ -154,18 +168,21 @@ describe("generator:config", () => { }); describe("yaml-space-set-to-4", () => { + let workDir = ""; beforeAll(() => - run(generatorDir).withPrompts( - getPromptConfig({ - enableAllContributors: true, - indentYamlSize: 4, - }) - ) + run(generatorDir) + .withPrompts( + getPromptConfig({ + enableAllContributors: true, + indentYamlSize: 4, + }) + ) + .inTmpDir((dir) => (workDir = dir)) ); it("creates all-contributorsrc with expected content", () => { assert.equalsFileContent( - "GitReleaseManager.yaml", + join(workDir, "GitReleaseManager.yaml"), readFileSync( join(__dirname, "expected/space/GitReleaseManager.yaml"), { diff --git a/__tests__/contributing/indexTests.ts b/__tests__/contributing/indexTests.ts index fe7c95b1..90566dc7 100644 --- a/__tests__/contributing/indexTests.ts +++ b/__tests__/contributing/indexTests.ts @@ -8,15 +8,20 @@ const generatorDir = join(__dirname, "../../src/contributing"); describe("generator:contributing", () => { describe("default", () => { - beforeAll(() => run(generatorDir).withPrompts(getPromptConfig())); + let workDir = ""; + beforeAll(() => + run(generatorDir) + .withPrompts(getPromptConfig()) + .inTmpDir((dir) => (workDir = dir)) + ); it("creates contributing file", () => { - assert.file("CONTRIBUTING.md"); + assert.file(join(workDir, "CONTRIBUTING.md")); }); it("creates file with expected content", () => { assert.equalsFileContent( - "CONTRIBUTING.md", + join(workDir, "CONTRIBUTING.md"), readFileSync(join(__dirname, "expected.md"), { encoding: "utf8" }) ); }); diff --git a/__tests__/license/indexTests.ts b/__tests__/license/indexTests.ts index 15ee1ca7..04b5680c 100644 --- a/__tests__/license/indexTests.ts +++ b/__tests__/license/indexTests.ts @@ -4,7 +4,10 @@ import * as assert from "yeoman-assert"; import * as helpers from "yeoman-test"; import { getPromptConfig } from "../../defaultConfigs"; -function runHelper(licenseType: string, author: string = "Kim Nordmo") { +function runHelper( + licenseType: string, + author: string = "Kim Nordmo" +): helpers.RunContext { return helpers .run(path.join(__dirname, "../../src/license")) .withPrompts( @@ -30,15 +33,18 @@ const licenses = [ describe("generator:license", () => { for (const license of licenses) { describe(`${license.Name} License`, () => { - beforeAll(() => runHelper(license.Name)); + let workDir = ""; + beforeAll(() => + runHelper(license.Name).inTmpDir((dir) => (workDir = dir)) + ); it("should create license.txt", () => { - assert.file("LICENSE.txt"); + assert.file(path.join(workDir, "LICENSE.txt")); }); it("should create license with expected content", () => { assert.equalsFileContent( - "LICENSE.txt", + path.join(workDir, "LICENSE.txt"), readFileSync(path.join(__dirname, `${license.Name}.txt`), { encoding: "utf8", }) @@ -47,13 +53,15 @@ describe("generator:license", () => { if (!license.Author) { it("should not require author to be set", () => { + let workDir2 = ""; return helpers .run(path.join(__dirname, "../../src/license")) .withPrompts(getPromptConfig({ licenseType: license.Name })) .withOptions({ year: 2019 }) + .inTmpDir((dir) => (workDir2 = dir)) .then(() => { assert.equalsFileContent( - "LICENSE.txt", + path.join(workDir2, "LICENSE.txt"), readFileSync(path.join(__dirname, `${license.Name}.txt`), { encoding: "utf8", }) @@ -65,12 +73,15 @@ describe("generator:license", () => { } describe("custom location", () => { + let workDir = ""; beforeAll(() => - runHelper("Unlicense").withOptions({ out: "UNLICENSE.txt" }) + runHelper("Unlicense") + .withOptions({ out: "UNLICENSE.txt" }) + .inTmpDir((dir) => (workDir = dir)) ); it("should allow user to specify file with options", () => { - assert.file("UNLICENSE.txt"); + assert.file(path.join(workDir, "UNLICENSE.txt")); }); }); @@ -84,13 +95,17 @@ describe("generator:license", () => { ]; for (const license of licenseNames) { + let workDir = ""; it(`should reuse existing ${license} file`, () => { return runHelper("MIT") - .inTmpDir((tmpDir) => writeFileSync(path.join(tmpDir, license), "")) + .inTmpDir((tmpDir) => { + writeFileSync(path.join(tmpDir, license), ""); + workDir = tmpDir; + }) .then(() => { - assert.file(license); + assert.file(path.join(workDir, license)); if (license !== "LICENSE.txt") { - assert.noFile("LICENSE.txt"); + assert.noFile(path.join(workDir, "LICENSE.txt")); } }); }); diff --git a/__tests__/project/indexTests.ts b/__tests__/project/indexTests.ts index ee1d3c4b..c9d4f96a 100644 --- a/__tests__/project/indexTests.ts +++ b/__tests__/project/indexTests.ts @@ -24,6 +24,7 @@ function assertContent(testPath: string, contentPath: string) { describe("generator:project", () => { it("should not overwrite solution file if one exist", () => { + let workDir = ""; return helpers .run(generatorDir) .withOptions( @@ -34,26 +35,33 @@ describe("generator:project", () => { .inTmpDir((tmpDir) => { mkdirSync(path.join(tmpDir, "src")); writeFileSync(path.join(tmpDir, "src/Cake.TestApp.sln"), ""); + workDir = tmpDir; }) .then(() => { - assert.equalsFileContent("src/Cake.TestApp.sln", ""); + assert.equalsFileContent( + path.join(workDir, "src", "Cake.TestApp.sln"), + "" + ); }); }); it("should set up url to wyam documentation when enabled", () => { + let workDir = ""; return helpers .run(generatorDir) .withPrompts(getPromptConfig()) .withOptions({ "skip-dotnet": true }) + .inTmpDir((dir) => (workDir = dir)) .then(() => assert.fileContent( - "src/Cake.TestApp/Cake.TestApp.csproj", + path.join(workDir, "src", "Cake.TestApp/Cake.TestApp.csproj"), "https://admiringworm.github.io/Cake.TestApp" ) ); }); describe("default", () => { + let workDir = ""; beforeAll(() => { return helpers .run(generatorDir) @@ -66,95 +74,133 @@ describe("generator:project", () => { .withOptions({ "skip-dotnet": true, "start-year": 2018, - }); + }) + .inTmpDir((dir) => (workDir = dir)); }); it("should create expected files", () => { - assert.file([ - "src/Cake.TestApp.sln", - "src/Cake.TestApp/Cake.TestApp.csproj", - "src/Cake.TestApp/TestAppAliases.cs", - "src/Cake.TestApp/TestAppRunner.cs", - "src/Cake.TestApp/TestAppSettings.cs", - "src/Cake.TestApp.Tests/Cake.TestApp.Tests.csproj", - "src/Cake.TestApp.Tests/TestAppAliasesFixture.cs", - "src/Cake.TestApp.Tests/TestAppAliasesTests.cs", - "src/Cake.TestApp.Tests/TestAppRunnerFixture.cs", - "src/Cake.TestApp.Tests/TestAppRunnerTests.cs", - ]); + assert.file( + [ + "src/Cake.TestApp.sln", + "src/Cake.TestApp/Cake.TestApp.csproj", + "src/Cake.TestApp/TestAppAliases.cs", + "src/Cake.TestApp/TestAppRunner.cs", + "src/Cake.TestApp/TestAppSettings.cs", + "src/Cake.TestApp.Tests/Cake.TestApp.Tests.csproj", + "src/Cake.TestApp.Tests/TestAppAliasesFixture.cs", + "src/Cake.TestApp.Tests/TestAppAliasesTests.cs", + "src/Cake.TestApp.Tests/TestAppRunnerFixture.cs", + "src/Cake.TestApp.Tests/TestAppRunnerTests.cs", + ].map((v) => path.join(workDir, v)) + ); }); it("should create main project file with expected content", () => { assertContent( - "src/Cake.TestApp/Cake.TestApp.csproj", + path.join(workDir, "src", "Cake.TestApp", "Cake.TestApp.csproj"), "default/project/project.csproj" ); }); it("should create Aliases class with expected content", () => { - assertContent("src/Cake.TestApp/TestAppAliases.cs", "default/aliases.cs"); + assertContent( + path.join(workDir, "src", "Cake.TestApp", "TestAppAliases.cs"), + "default/aliases.cs" + ); }); it("should create Runner class with expected content", () => { - assertContent("src/Cake.TestApp/TestAppRunner.cs", "default/runner.cs"); + assertContent( + path.join(workDir, "src", "Cake.TestApp", "TestAppRunner.cs"), + "default/runner.cs" + ); }); it("should create Settings class with expected content", () => { assertContent( - "src/Cake.TestApp/TestAppSettings.cs", + path.join(workDir, "src", "Cake.TestApp", "TestAppSettings.cs"), "default/settings.cs" ); }); it("should create Aliases fixture class with expected content", () => { assertContent( - "src/Cake.TestApp.Tests/TestAppAliasesFixture.cs", + path.join( + workDir, + "src", + "Cake.TestApp.Tests", + "TestAppAliasesFixture.cs" + ), "default/testAliasesFixture.cs" ); }); it("should create Runner fixture class with expected content", () => { assertContent( - "src/Cake.TestApp.Tests/TestAppRunnerFixture.cs", + path.join( + workDir, + "src", + "Cake.TestApp.Tests", + "TestAppRunnerFixture.cs" + ), "default/testRunnerFixture.cs" ); }); describe("xunit", () => { + let workDir2 = ""; beforeAll(() => { return helpers .run(generatorDir) .withPrompts(getPromptConfig()) .withOptions({ "skip-dotnet": true, - }); + }) + .inTmpDir((dir) => (workDir2 = dir)); }); it("should create expected files", () => { - assert.file([ - "src/Cake.TestApp.Tests/Cake.TestApp.Tests.csproj", - "src/Cake.TestApp.Tests/TestAppAliasesTests.cs", - "src/Cake.TestApp.Tests/TestAppRunnerTests.cs", - ]); + assert.file( + [ + "src/Cake.TestApp.Tests/Cake.TestApp.Tests.csproj", + "src/Cake.TestApp.Tests/TestAppAliasesTests.cs", + "src/Cake.TestApp.Tests/TestAppRunnerTests.cs", + ].map((v) => path.join(workDir2, v)) + ); }); it("should create test project file with expected content", () => { assertContent( - "src/Cake.TestApp.Tests/Cake.TestApp.Tests.csproj", + path.join( + workDir2, + "src", + "Cake.TestApp.Tests", + "Cake.TestApp.Tests.csproj" + ), "default/xunit/testProject/testProject.csproj" ); }); it("should create aliases test class with expected content", () => { assertContent( - "src/Cake.TestApp.Tests/TestAppAliasesTests.cs", + path.join( + workDir2, + "src", + "Cake.TestApp.Tests", + "TestAppAliasesTests.cs" + ), "default/xunit/testAliasesTests.cs" ); }); it("should create runner test class with expected content", () => { assertContent( - "src/Cake.TestApp.Tests/TestAppRunnerTests.cs", + path.join( + workDir2, + "src", + "Cake.TestApp.Tests", + "TestAppRunnerTests.cs" + ), "default/xunit/testRunnerTests.cs" ); }); @@ -163,14 +209,19 @@ describe("generator:project", () => { describe("custom-source-directory", () => { it("should allow changing source directory through prompts", () => { + let workDir = ""; return helpers .run(generatorDir) .withPrompts(getPromptConfig({ sourceDir: "./source" })) .withOptions({ "skip-dotnet": true }) - .then(() => assert.file("source/Cake.TestApp.sln")); + .inTmpDir((dir) => (workDir = dir)) + .then(() => + assert.file(path.join(workDir, "source", "Cake.TestApp.sln")) + ); }); it("should allow changing source directory through options", () => { + let workDir = ""; return helpers .run(generatorDir) .withOptions( @@ -179,44 +230,60 @@ describe("generator:project", () => { sourceDir: "./source", }) ) - .then(() => assert.file("source/Cake.TestApp.sln")); + .inTmpDir((dir) => (workDir = dir)) + .then(() => + assert.file(path.join(workDir, "source", "Cake.TestApp.sln")) + ); }); }); if (!skipDotnet) { describe("dotnet restore", () => { + let workDir = ""; beforeAll(() => { - return helpers.run(generatorDir).withPrompts(getPromptConfig()); + return helpers + .run(generatorDir) + .withPrompts(getPromptConfig({ build: false })) + .inTmpDir((dir) => (workDir = dir)); }); it("should run dotnet restore by default", () => { - assert.file([ - "src/Cake.TestApp/obj/project.nuget.cache", - "src/Cake.TestApp.Tests/obj/project.nuget.cache", - ]); + assert.file( + [ + "src/Cake.TestApp/obj/project.nuget.cache", + "src/Cake.TestApp.Tests/obj/project.nuget.cache", + ].map((v) => path.join(workDir, v)) + ); }); }); describe("dotnet build", () => { + let workDir = ""; beforeAll(() => { - return helpers.run(generatorDir).withOptions( - getPromptConfig({ - build: true, - }) - ); + return helpers + .run(generatorDir) + .withOptions( + getPromptConfig({ + build: true, + }) + ) + .inTmpDir((dir) => (workDir = dir)); }); it("should run dotnet build when --build is specified", () => { - assert.file([ - "src/Cake.TestApp/bin/Debug/netstandard2.0/Cake.TestApp.dll", - "src/Cake.TestApp/bin/Debug/net461/Cake.TestApp.dll", - "src/Cake.TestApp.Tests/bin/Debug/netcoreapp2.0/Cake.TestApp.Tests.dll", - ]); + assert.file( + [ + "src/Cake.TestApp/bin/Debug/netstandard2.0/Cake.TestApp.dll", + "src/Cake.TestApp/bin/Debug/net461/Cake.TestApp.dll", + "src/Cake.TestApp.Tests/bin/Debug/netcoreapp2.0/Cake.TestApp.Tests.dll", + ].map((v) => path.join(workDir, v)) + ); }); }); } describe("indentation", () => { describe("tabs", () => { + let workDir = ""; beforeAll(() => { return helpers .run(generatorDir) @@ -230,15 +297,19 @@ describe("generator:project", () => { .withOptions({ "skip-dotnet": true, "start-year": 2019, - }); + }) + .inTmpDir((dir) => (workDir = dir)); }); const tabRegex = /^($|\t*[^\s])/; it("should create solution file with tabs instead of spaces", () => { - const buffer = readFileSync("src/Cake.TestApp.sln", { - encoding: "utf-8", - }); + const buffer = readFileSync( + path.join(workDir, "src", "Cake.TestApp.sln"), + { + encoding: "utf-8", + } + ); const lines = buffer.toString().split(/\r?\n/g); lines.forEach((line) => { @@ -247,9 +318,12 @@ describe("generator:project", () => { }); it("should create project file with tabs instead of spaces", () => { - const buffer = readFileSync("src/Cake.TestApp/Cake.TestApp.csproj", { - encoding: "utf-8", - }); + const buffer = readFileSync( + path.join(workDir, "src", "Cake.TestApp/Cake.TestApp.csproj"), + { + encoding: "utf-8", + } + ); const lines = buffer.toString().split(/\r?\n/g); lines.forEach((line) => { @@ -258,9 +332,12 @@ describe("generator:project", () => { }); it("should create aliases file with tabs instead of spaces", () => { - const buffer = readFileSync("src/Cake.TestApp/TestAppAliases.cs", { - encoding: "utf-8", - }); + const buffer = readFileSync( + path.join(workDir, "src", "Cake.TestApp", "TestAppAliases.cs"), + { + encoding: "utf-8", + } + ); const lines = buffer.toString().split(/\r?\n/g); lines.forEach((line) => { @@ -269,9 +346,12 @@ describe("generator:project", () => { }); it("should create Runner file with tabs instead of spaces", () => { - const buffer = readFileSync("src/Cake.TestApp/TestAppRunner.cs", { - encoding: "utf-8", - }); + const buffer = readFileSync( + path.join(workDir, "src", "Cake.TestApp", "TestAppRunner.cs"), + { + encoding: "utf-8", + } + ); const lines = buffer.toString().split(/\r?\n/g); lines.forEach((line) => { @@ -280,9 +360,12 @@ describe("generator:project", () => { }); it("should create settings file with tabs instead of spaces", () => { - const buffer = readFileSync("src/Cake.TestApp/TestAppSettings.cs", { - encoding: "utf-8", - }); + const buffer = readFileSync( + path.join(workDir, "src", "Cake.TestApp", "TestAppSettings.cs"), + { + encoding: "utf-8", + } + ); const lines = buffer.toString().split(/\r?\n/g); lines.forEach((line) => { @@ -292,7 +375,12 @@ describe("generator:project", () => { it("should create test project file with tabs instead of spaces", () => { const buffer = readFileSync( - "src/Cake.TestApp.Tests/Cake.TestApp.Tests.csproj", + path.join( + workDir, + "src", + "Cake.TestApp.Tests", + "Cake.TestApp.Tests.csproj" + ), { encoding: "utf-8", } @@ -306,7 +394,12 @@ describe("generator:project", () => { it("should create test aliases fixture file with tabs instead of spaces", () => { const buffer = readFileSync( - "src/Cake.TestApp.Tests/TestAppAliasesFixture.cs", + path.join( + workDir, + "src", + "Cake.TestApp.Tests", + "TestAppAliasesFixture.cs" + ), { encoding: "utf-8", } @@ -320,7 +413,12 @@ describe("generator:project", () => { it("should create test aliases file with tabs instead of spaces", () => { const buffer = readFileSync( - "src/Cake.TestApp.Tests/TestAppAliasesTests.cs", + path.join( + workDir, + "src", + "Cake.TestApp.Tests", + "TestAppAliasesTests.cs" + ), { encoding: "utf-8", } @@ -334,7 +432,12 @@ describe("generator:project", () => { it("should create test Runner fixture file with tabs instead of spaces", () => { const buffer = readFileSync( - "src/Cake.TestApp.Tests/TestAppRunnerFixture.cs", + path.join( + workDir, + "src", + "Cake.TestApp.Tests", + "TestAppRunnerFixture.cs" + ), { encoding: "utf-8", } @@ -348,7 +451,12 @@ describe("generator:project", () => { it("should create test runner file with tabs instead of spaces", () => { const buffer = readFileSync( - "src/Cake.TestApp.Tests/TestAppRunnerTests.cs", + path.join( + workDir, + "src", + "Cake.TestApp.Tests", + "TestAppRunnerTests.cs" + ), { encoding: "utf-8", } @@ -362,6 +470,7 @@ describe("generator:project", () => { }); describe("space", () => { + let workDir = ""; beforeAll(() => { return helpers .run(generatorDir) @@ -375,62 +484,94 @@ describe("generator:project", () => { .withOptions({ "skip-dotnet": true, "start-year": 2018, - }); + }) + .inTmpDir((dir) => (workDir = dir)); }); it("should indent Aliases class with 2 spaces", () => { - assertContent("src/Cake.TestApp/TestAppAliases.cs", "space/aliases.cs"); + assertContent( + path.join(workDir, "src", "Cake.TestApp", "TestAppAliases.cs"), + "space/aliases.cs" + ); }); it("should indent Project file with 2 spaces", () => { assertContent( - "src/Cake.TestApp/Cake.TestApp.csproj", + path.join(workDir, "src", "Cake.TestApp", "Cake.TestApp.csproj"), "space/project.csproj" ); }); it("should indent Runner class with 2 spaces", () => { - assertContent("src/Cake.TestApp/TestAppRunner.cs", "space/runner.cs"); + assertContent( + path.join(workDir, "src", "Cake.TestApp", "TestAppRunner.cs"), + "space/runner.cs" + ); }); it("should indent Settings class with 2 spaces", () => { assertContent( - "src/Cake.TestApp/TestAppSettings.cs", + path.join(workDir, "src", "Cake.TestApp", "TestAppSettings.cs"), "space/settings.cs" ); }); it("should indent Aliases Fixture class with 2 spaces", () => { assertContent( - "src/Cake.TestApp.Tests/TestAppAliasesFixture.cs", + path.join( + workDir, + "src", + "Cake.TestApp.Tests", + "TestAppAliasesFixture.cs" + ), "space/testAliasesFixture.cs" ); }); it("should indent Aliases Tests class with 2 spaces", () => { assertContent( - "src/Cake.TestApp.Tests/TestAppAliasesTests.cs", + path.join( + workDir, + "src", + "Cake.TestApp.Tests", + "TestAppAliasesTests.cs" + ), "space/testAliasesTests.cs" ); }); it("should indent Test Project file with 2 spaces", () => { assertContent( - "src/Cake.TestApp.Tests/Cake.TestApp.Tests.csproj", + path.join( + workDir, + "src", + "Cake.TestApp.Tests", + "Cake.TestApp.Tests.csproj" + ), "space/testProject.csproj" ); }); it("should indent Runner Fixture class with 2 spaces", () => { assertContent( - "src/Cake.TestApp.Tests/TestAppRunnerFixture.cs", + path.join( + workDir, + "src", + "Cake.TestApp.Tests", + "TestAppRunnerFixture.cs" + ), "space/testRunnerFixture.cs" ); }); it("should indent Runner Tests class with 2 spaces", () => { assertContent( - "src/Cake.TestApp.Tests/TestAppRunnerTests.cs", + path.join( + workDir, + "src", + "Cake.TestApp.Tests", + "TestAppRunnerTests.cs" + ), "space/testRunnerTests.cs" ); }); diff --git a/__tests__/readme/indexTests.ts b/__tests__/readme/indexTests.ts index f72ed2b5..3d23ab4e 100644 --- a/__tests__/readme/indexTests.ts +++ b/__tests__/readme/indexTests.ts @@ -1,4 +1,4 @@ -import { readFileSync, writeFileSync } from "fs"; +import { existsSync, readFileSync, unlinkSync, writeFileSync } from "fs"; import * as path from "path"; import * as assert from "yeoman-assert"; import * as helpers from "yeoman-test"; @@ -8,45 +8,59 @@ const generatorDir = path.join(__dirname, "../../src/readme"); describe("generator:Readme", () => { describe("basic", () => { + let workDir = ""; beforeAll(() => - helpers.run(generatorDir).withPrompts( - getPromptConfig({ - description: "The most awesome test cake addin library.", + helpers + .run(generatorDir) + .withPrompts( + getPromptConfig({ + description: "The most awesome test cake addin library.", + }) + ) + .inTmpDir((dir) => { + workDir = dir; + writeFileSync(path.join(dir, "LICENSE.txt"), ""); }) - ) ); it("should create readme file", () => { - assert.file("README.md"); + assert.file(path.join(workDir, "README.md")); }); it("should have expected content", () => { assert.equalsFileContent( - "README.md", + path.join(workDir, "README.md"), readFileSync(path.join(__dirname, "basic.md"), { encoding: "utf8" }) ); }); }); describe("basic with long description", () => { + let workDir = ""; beforeAll(() => - helpers.run(generatorDir).withPrompts( - getPromptConfig({ - description: - "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam tincidunt, nisl tincidunt convallis iaculis, tellus ante mattis dui, ac tincidunt libero nibh non tortor. Ut condimentum erat in mi efficitur fringilla. Mauris pellentesque, nulla et viverra rutrum, justo tortor condimentum augue, vitae commodo mauris enim interdum nibh. Vestibulum non dictum velit, in porta nisi. Mauris eu pulvinar urna. Nulla congue turpis eu felis aliquam faucibus. Ut eget orci vehicula turpis euismod faucibus. Curabitur ut eros vel massa feugiat ultricies. Praesent elit velit, elementum et velit sed, faucibus interdum odio. Aliquam interdum mi urna, fermentum maximus elit facilisis eget. Morbi facilisis lectus non odio eleifend rhoncus ac egestas felis. Sed eget nisi mollis, ornare risus id, ultricies quam. Sed et nulla consequat, mollis risus eu, iaculis leo. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec placerat sem sit amet vestibulum cursus. Sed feugiat ultrices lectus, interdum vehicula enim luctus et.\n\nNam sodales nisl sit amet libero pharetra, eu vestibulum nibh auctor. Vestibulum vitae erat sapien. Proin bibendum sagittis lectus quis posuere. Proin aliquam eu ipsum sit amet sodales. Proin ultricies mollis sem, nec consectetur risus facilisis at. Donec nec tincidunt dui, non viverra elit. Praesent a magna nec dui elementum vestibulum vel quis nunc. Pellentesque sed enim sit amet tortor mollis tincidunt. Phasellus quis lacinia libero. Ut et vestibulum diam. Maecenas efficitur odio et lacus maximus porta non at ante. Aliquam nulla ex, blandit non interdum in, congue quis tortor. Morbi maximus urna sem, sit amet gravida augue tincidunt sit amet. Maecenas mollis sapien enim, sed pharetra augue porta vel.", - shortDescription: - "Lorem ipsum dolor sit amet, consectetur cras amet.", + helpers + .run(generatorDir) + .withPrompts( + getPromptConfig({ + description: + "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam tincidunt, nisl tincidunt convallis iaculis, tellus ante mattis dui, ac tincidunt libero nibh non tortor. Ut condimentum erat in mi efficitur fringilla. Mauris pellentesque, nulla et viverra rutrum, justo tortor condimentum augue, vitae commodo mauris enim interdum nibh. Vestibulum non dictum velit, in porta nisi. Mauris eu pulvinar urna. Nulla congue turpis eu felis aliquam faucibus. Ut eget orci vehicula turpis euismod faucibus. Curabitur ut eros vel massa feugiat ultricies. Praesent elit velit, elementum et velit sed, faucibus interdum odio. Aliquam interdum mi urna, fermentum maximus elit facilisis eget. Morbi facilisis lectus non odio eleifend rhoncus ac egestas felis. Sed eget nisi mollis, ornare risus id, ultricies quam. Sed et nulla consequat, mollis risus eu, iaculis leo. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec placerat sem sit amet vestibulum cursus. Sed feugiat ultrices lectus, interdum vehicula enim luctus et.\n\nNam sodales nisl sit amet libero pharetra, eu vestibulum nibh auctor. Vestibulum vitae erat sapien. Proin bibendum sagittis lectus quis posuere. Proin aliquam eu ipsum sit amet sodales. Proin ultricies mollis sem, nec consectetur risus facilisis at. Donec nec tincidunt dui, non viverra elit. Praesent a magna nec dui elementum vestibulum vel quis nunc. Pellentesque sed enim sit amet tortor mollis tincidunt. Phasellus quis lacinia libero. Ut et vestibulum diam. Maecenas efficitur odio et lacus maximus porta non at ante. Aliquam nulla ex, blandit non interdum in, congue quis tortor. Morbi maximus urna sem, sit amet gravida augue tincidunt sit amet. Maecenas mollis sapien enim, sed pharetra augue porta vel.", + shortDescription: + "Lorem ipsum dolor sit amet, consectetur cras amet.", + }) + ) + .inTmpDir((dir) => { + workDir = dir; + writeFileSync(path.join(dir, "LICENSE.txt"), ""); }) - ) ); it("should create readme file", () => { - assert.file("README.md"); + assert.file(path.join(workDir, "README.md")); }); it("should have expected content", () => { assert.equalsFileContent( - "README.md", + path.join(workDir, "README.md"), readFileSync(path.join(__dirname, "basic_with_long_text.md"), { encoding: "utf8", }) @@ -55,22 +69,29 @@ describe("generator:Readme", () => { }); describe("basic with travis enabled", () => { + let workDir = ""; beforeAll(() => - helpers.run(generatorDir).withPrompts( - getPromptConfig({ - description: "The most awesome test cake addin library.", - enableTravis: true, + helpers + .run(generatorDir) + .withPrompts( + getPromptConfig({ + description: "The most awesome test cake addin library.", + enableTravis: true, + }) + ) + .inTmpDir((dir) => { + workDir = dir; + writeFileSync(path.join(dir, "LICENSE.txt"), ""); }) - ) ); it("should create readme file", () => { - assert.file("README.md"); + assert.file(path.join(workDir, "README.md")); }); it("should have expected content", () => { assert.equalsFileContent( - "README.md", + path.join(workDir, "README.md"), readFileSync(path.join(__dirname, "basic_with_travis.md"), { encoding: "utf8", }) @@ -79,6 +100,7 @@ describe("generator:Readme", () => { }); describe("basic with travis enabled when travis file exist", () => { + let workDir = ""; beforeAll(() => helpers .run(generatorDir) @@ -88,17 +110,19 @@ describe("generator:Readme", () => { }) ) .inTmpDir((tmpDir) => { + workDir = tmpDir; writeFileSync(path.join(tmpDir, ".travis.yml"), ""); + writeFileSync(path.join(tmpDir, "LICENSE.txt"), ""); }) ); it("should create readme file", () => { - assert.file("README.md"); + assert.file(path.join(workDir, "README.md")); }); it("should have expected content", () => { assert.equalsFileContent( - "README.md", + path.join(workDir, "README.md"), readFileSync(path.join(__dirname, "basic_with_travis.md"), { encoding: "utf8", }) @@ -107,22 +131,29 @@ describe("generator:Readme", () => { }); describe("basic with contributing enabled", () => { + let workDir = ""; beforeAll(() => - helpers.run(generatorDir).withPrompts( - getPromptConfig({ - description: "The most awesome test cake addin library.", - enableContributing: true, + helpers + .run(generatorDir) + .withPrompts( + getPromptConfig({ + description: "The most awesome test cake addin library.", + enableContributing: true, + }) + ) + .inTmpDir((dir) => { + workDir = dir; + writeFileSync(path.join(dir, "LICENSE.txt"), ""); }) - ) ); it("should create readme file", () => { - assert.file("README.md"); + assert.file(path.join(workDir, "README.md")); }); it("should have expected content", () => { assert.equalsFileContent( - "README.md", + path.join(workDir, "README.md"), readFileSync(path.join(__dirname, "basic_with_contributing.md"), { encoding: "utf8", }) @@ -131,6 +162,7 @@ describe("generator:Readme", () => { }); describe("basic with contributing enabled when CONTRIBUTING.md file exist", () => { + let workDir = ""; beforeAll(() => helpers .run(generatorDir) @@ -140,17 +172,19 @@ describe("generator:Readme", () => { }) ) .inTmpDir((tmpDir) => { + workDir = tmpDir; writeFileSync(path.join(tmpDir, "CONTRIBUTING.md"), ""); + writeFileSync(path.join(tmpDir, "LICENSE.txt"), ""); }) ); it("should create readme file", () => { - assert.file("README.md"); + assert.file(path.join(workDir, "README.md")); }); it("should have expected content", () => { assert.equalsFileContent( - "README.md", + path.join(workDir, "README.md"), readFileSync(path.join(__dirname, "basic_with_contributing.md"), { encoding: "utf8", }) @@ -159,22 +193,29 @@ describe("generator:Readme", () => { }); describe("basic with all contributors enabled", () => { + let workDir = ""; beforeAll(() => - helpers.run(generatorDir).withPrompts( - getPromptConfig({ - description: "The most awesome test cake addin library.", - enableAllContributors: true, + helpers + .run(generatorDir) + .withPrompts( + getPromptConfig({ + description: "The most awesome test cake addin library.", + enableAllContributors: true, + }) + ) + .inTmpDir((dir) => { + workDir = dir; + writeFileSync(path.join(dir, "LICENSE.txt"), ""); }) - ) ); it("should create readme file", () => { - assert.file("README.md"); + assert.file(path.join(workDir, "README.md")); }); it("should have expected content", () => { assert.equalsFileContent( - "README.md", + path.join(workDir, "README.md"), readFileSync(path.join(__dirname, "basic_with_allcontributors.md"), { encoding: "utf8", }) @@ -183,21 +224,28 @@ describe("generator:Readme", () => { }); describe("with options", () => { + let workDir = ""; beforeAll(() => - helpers.run(generatorDir).withOptions( - getPromptConfig({ - description: "The most awesome test cake addin library.", + helpers + .run(generatorDir) + .withOptions( + getPromptConfig({ + description: "The most awesome test cake addin library.", + }) + ) + .inTmpDir((dir) => { + workDir = dir; + writeFileSync(path.join(dir, "LICENSE.txt"), ""); }) - ) ); it("should create readme file", () => { - assert.file("README.md"); + assert.file(path.join(workDir, "README.md")); }); it("should have expected content", () => { assert.equalsFileContent( - "README.md", + path.join(workDir, "README.md"), readFileSync(path.join(__dirname, "basic.md"), { encoding: "utf8" }) ); }); @@ -212,8 +260,18 @@ describe("generator:Readme", () => { "LICENSE.txt", ]; + function removeExistingLicenses(workDir: string) { + for (const license of licenses) { + const licensePath = path.join(workDir, license); + if (existsSync(licensePath)) { + unlinkSync(licensePath); + } + } + } + for (const license of licenses) { it(`should link to existing license: ${license}`, () => { + let workDir = ""; return helpers .run(generatorDir) .withPrompts( @@ -221,10 +279,14 @@ describe("generator:Readme", () => { description: "The most awesome test cake addin library.", }) ) - .inTmpDir((tmpDir) => writeFileSync(path.join(tmpDir, license), "")) + .inTmpDir((tmpDir) => { + workDir = tmpDir; + removeExistingLicenses(tmpDir); + writeFileSync(path.join(tmpDir, license), ""); + }) .then(() => { assert.fileContent( - "README.md", + path.join(workDir, "README.md"), new RegExp(`\\[license\\]:\\s*${license}[\\r\\n]`) ); }); diff --git a/__tests__/travis/indexTests.ts b/__tests__/travis/indexTests.ts index 01bc813e..f6127b7e 100644 --- a/__tests__/travis/indexTests.ts +++ b/__tests__/travis/indexTests.ts @@ -8,11 +8,13 @@ const generatorDir = path.join(__dirname, "../../src/travis"); describe("generator:travis", () => { describe("default", () => { + let workDir = ""; beforeEach(() => { return helpers .run(generatorDir) .withPrompts(getPromptConfig()) .inTmpDir((tmpDir) => { + workDir = tmpDir; fs.writeFileSync( path.join(tmpDir, "package.json"), '{"name": "Cake.Foo", "files":[]}' @@ -21,12 +23,12 @@ describe("generator:travis", () => { }); it("creates travis build file", () => { - assert.file([".travis.yml"]); + assert.file(path.join(workDir, ".travis.yml")); }); it("fills travis.yml file with expected content", () => { assert.equalsFileContent( - ".travis.yml", + path.join(workDir, ".travis.yml"), `language: csharp dist: xenial os: @@ -62,11 +64,13 @@ script: }); describe("custom indent", () => { + let workDir = ""; beforeEach(() => { return helpers .run(generatorDir) .withPrompts(getPromptConfig({ indentYamlSize: 4 })) .inTmpDir((tmpDir) => { + workDir = tmpDir; fs.writeFileSync( path.join(tmpDir, "package.json"), '{"name": "Cake.Foo", "files":[]}' @@ -75,12 +79,12 @@ script: }); it("creates travis build file", () => { - assert.file([".travis.yml"]); + assert.file(path.join(workDir, ".travis.yml")); }); it("fills travis.yml file with expected content", () => { assert.equalsFileContent( - ".travis.yml", + path.join(workDir, ".travis.yml"), `language: csharp dist: xenial os: