From 5779d08827ed7d6bb2f74756504a2d30d7e04b09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=CC=88zu=CC=88m=20Eldog=CC=86an?= Date: Sat, 13 Mar 2021 10:00:08 +0300 Subject: [PATCH] fix: fix ci workflow --- github.env => .github/workflows/github.env | 2 +- .github/workflows/main.yml | 2 +- test/generate.test.ts | 6 +----- test/test-helper/global-setup.ts | 6 ++++++ 4 files changed, 9 insertions(+), 7 deletions(-) rename github.env => .github/workflows/github.env (63%) diff --git a/github.env b/.github/workflows/github.env similarity index 63% rename from github.env rename to .github/workflows/github.env index 5817347..d0d517d 100644 --- a/github.env +++ b/.github/workflows/github.env @@ -1,4 +1,4 @@ -DB_DATABASE=example +DB_DATABASE=pg-generator-test DB_HOST=localhost DB_USER=user DB_PASSWORD=password diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f6e170f..a286c78 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -31,7 +31,7 @@ jobs: run: |- while read line; do echo "$line" >> $GITHUB_ENV - done < github.env + done < .github/workflows/github.env - name: Use Node 14 uses: actions/setup-node@v2 with: diff --git a/test/generate.test.ts b/test/generate.test.ts index d9bc5c1..7c99e72 100644 --- a/test/generate.test.ts +++ b/test/generate.test.ts @@ -10,7 +10,6 @@ const TEST_ROOT = join(tmpdir(), "pgen"); const outDir = join(TEST_ROOT, "out"); const outDir2 = join(TEST_ROOT, "out2"); const app = new App({ outDir }, { db: {}, templateDir: join(__dirname, "templates") } as any); -const CLIENT_OPTIONS = { database: "pg-generator-test", user: "user", password: "password" }; // WORKAROUND: Jest does not output error of dynamic import in (src/utils/compose-with.ts). This function rethrows error. async function g(subGenerator = "app", options?: Options, { argLength = 3, cwd = "" } = {}): ReturnType { @@ -25,7 +24,6 @@ async function g(subGenerator = "app", options?: Options, { argLength = 3, cwd = log: false, outDir, relationNameFunctions: "optimal", - ...CLIENT_OPTIONS, ...options, }; @@ -116,9 +114,7 @@ describe("generate", () => { }); it("should throw if generator cannot be found.", async () => { - await expect(() => generate("XYZ", { ...CLIENT_OPTIONS })).rejects.toThrow( - "You don't seem to have a generator with the name 'XYZ' installed." - ); + await expect(() => generate("XYZ")).rejects.toThrow("You don't seem to have a generator with the name 'XYZ' installed."); }); it("should throw if sub-generator cannot be found.", async () => { diff --git a/test/test-helper/global-setup.ts b/test/test-helper/global-setup.ts index 9cda6fb..427d118 100644 --- a/test/test-helper/global-setup.ts +++ b/test/test-helper/global-setup.ts @@ -1,6 +1,12 @@ +import { promises as fs, existsSync } from "fs"; +import { join } from "path"; import PgTestUtil from "pg-test-util"; module.exports = async () => { + const envPath = join(__dirname, "../../.env"); + const githubEnvPath = join(__dirname, "../../.github/workflows/github.env"); + if (!existsSync(envPath)) await fs.copyFile(githubEnvPath, envPath); + const pgTestUtil = new PgTestUtil({ connection: { connectionString: "postgresql://user:password@127.0.0.1:5432/template1" } }); await pgTestUtil.createDatabase({ drop: true, name: "pg-generator-test", file: `${__dirname}/ddl/main.sql` }); (global as any).pgTestUtil = pgTestUtil;