From d9fb7b2e8d46c52b6557d441424698a667883fb2 Mon Sep 17 00:00:00 2001 From: Tobias Lundin Date: Sat, 19 Nov 2022 22:15:43 +0100 Subject: [PATCH 1/7] add ci workflow to run tests in windows/ubuntu --- .github/workflows/ci-test.yml | 26 ++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci-test.yml diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml new file mode 100644 index 0000000..6bfffa4 --- /dev/null +++ b/.github/workflows/ci-test.yml @@ -0,0 +1,26 @@ +name: Node.js CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + + steps: + - uses: actions/checkout@v3 + + - name: Use Node LTS + uses: actions/setup-node@v3 + + with: + node-version: lts/* + - run: npm ci + - run: npm test \ No newline at end of file diff --git a/package.json b/package.json index bd98215..2f64d06 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "src/" ], "scripts": { - "test": "npx -y rome check . && vitest run", + "test": "npx -y rome check . && vitest run --reporter verbose", "tdd": "vitest", "fix": "npx -y rome format . --write", "publish:dev": "npx -y np prerelease --tag=next --any-branch --no-release-draft", From eb7bee23ce1709d5ea2178d22a54778d4b7aff0b Mon Sep 17 00:00:00 2001 From: Tobias Lundin Date: Sat, 19 Nov 2022 22:27:24 +0100 Subject: [PATCH 2/7] add more output test only on windows --- .github/workflows/ci-test.yml | 2 +- cli.js | 1 + test/utils.test.js | 11 +++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 6bfffa4..fee852e 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: - os: [ubuntu-latest, windows-latest] + os: [windows-latest] # ubuntu-latest, mac-latest steps: - uses: actions/checkout@v3 diff --git a/cli.js b/cli.js index 34c4179..2f560ad 100644 --- a/cli.js +++ b/cli.js @@ -66,6 +66,7 @@ console.log(`\nRunning ${pc.green(`${pc.bold('mkcert-cli')}`)} (${pkgVersion})\n (dryRun || verbose) && console.log(`${pc.bold('With options:')} - ${pc.blue('cwd')}: ${pc.yellow(cwd)} + - ${pc.blue('dataDir')}: ${pc.yellow(DATA_DIR)} - ${pc.blue('outDir')}: ${pc.yellow(outDir)} - ${pc.blue('hosts')}: ${JSON.stringify(hosts)} - ${pc.blue('cert')}: ${certFile} diff --git a/test/utils.test.js b/test/utils.test.js index 220680c..5ec242f 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -5,6 +5,17 @@ import pkgJson from '../package.json' assert { type: 'json' }; import { dirname, join, resolve } from 'path'; import { homedir } from 'os'; +describe('--dryRun', () => { + it('more of a debug print session for CI', async () => { + const cliPathAbs = getAbsolutePath('../cli.js', import.meta.url); + const cmd = `node ${cliPathAbs} --dryRun`; + const { stdout } = await exec(cmd, { cwd: homedir(), env: { ...process.env } }); + console.log(` + ${stdout} + `); + }); +}); + describe('semverGreaterThan', () => { it('returns expected bool', () => { assert.ok(semverGreaterThan('v1.4.4', 'v.1.4.3')); From c66b2c4595ea0e46b9557904dbd97d5eaaa213fe Mon Sep 17 00:00:00 2001 From: Tobias Lundin Date: Sat, 19 Nov 2022 22:34:06 +0100 Subject: [PATCH 3/7] skip some tests --- test/utils.test.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/utils.test.js b/test/utils.test.js index 5ec242f..39fc7c9 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -9,6 +9,7 @@ describe('--dryRun', () => { it('more of a debug print session for CI', async () => { const cliPathAbs = getAbsolutePath('../cli.js', import.meta.url); const cmd = `node ${cliPathAbs} --dryRun`; + console.log('Running', cmd, new URL('..cli.js', import.meta.url).toString()); const { stdout } = await exec(cmd, { cwd: homedir(), env: { ...process.env } }); console.log(` ${stdout} @@ -16,7 +17,7 @@ describe('--dryRun', () => { }); }); -describe('semverGreaterThan', () => { +describe.skip('semverGreaterThan', () => { it('returns expected bool', () => { assert.ok(semverGreaterThan('v1.4.4', 'v.1.4.3')); assert.notOk(semverGreaterThan('v1.4.3', 'v.1.4.4')); @@ -24,7 +25,7 @@ describe('semverGreaterThan', () => { }); }); -describe('pkgJson', () => { +describe.skip('pkgJson', () => { it('matches asserted import value', () => { assert.equal(pkgVersion, `v${pkgJson.version}`); }); @@ -41,7 +42,7 @@ const testCertFolder = 'tstCertFolder'; const cmd = `node ${join(dirname(import.meta.url), '../cli.js').replace(/^file:/, '')}`; const rmTestDir = async () => await exec(`rm -rf ${testCertFolder}`, {}); -describe('cli', () => { +describe.skip('cli', () => { beforeEach(async () => { await rmTestDir(); }); From 337824db0c4f15555173618ab1275d8937875d53 Mon Sep 17 00:00:00 2001 From: Tobias Lundin Date: Sat, 19 Nov 2022 22:35:00 +0100 Subject: [PATCH 4/7] rename job to test --- .github/workflows/ci-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index fee852e..51f832f 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -7,7 +7,7 @@ on: branches: [ main ] jobs: - build: + test: runs-on: ${{ matrix.os }} strategy: From 75598a7ecbf011d8e80c740e416f053c67b99cb5 Mon Sep 17 00:00:00 2001 From: Tobias Lundin Date: Sat, 19 Nov 2022 22:40:26 +0100 Subject: [PATCH 5/7] more output to find issue --- test/utils.test.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/utils.test.js b/test/utils.test.js index 39fc7c9..1bbfeab 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -9,7 +9,12 @@ describe('--dryRun', () => { it('more of a debug print session for CI', async () => { const cliPathAbs = getAbsolutePath('../cli.js', import.meta.url); const cmd = `node ${cliPathAbs} --dryRun`; - console.log('Running', cmd, new URL('..cli.js', import.meta.url).toString()); + console.log('PLEASE READ THIS', { + cwd: process.cwd(), + cmd, + filePathURL: new URL('..cli.js', import.meta.url).toString(), + filePathResolve: resolve('../cli.js'), + }); const { stdout } = await exec(cmd, { cwd: homedir(), env: { ...process.env } }); console.log(` ${stdout} From 9092921d18dac89355e5ed962dd2458e3def590d Mon Sep 17 00:00:00 2001 From: Tobias Lundin Date: Sat, 19 Nov 2022 22:43:08 +0100 Subject: [PATCH 6/7] try using resolve --- test/utils.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/utils.test.js b/test/utils.test.js index 1bbfeab..c0d167b 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -7,7 +7,7 @@ import { homedir } from 'os'; describe('--dryRun', () => { it('more of a debug print session for CI', async () => { - const cliPathAbs = getAbsolutePath('../cli.js', import.meta.url); + const cliPathAbs = resolve('../cli.js'); const cmd = `node ${cliPathAbs} --dryRun`; console.log('PLEASE READ THIS', { cwd: process.cwd(), From 36de7d4b8aef7f8d474344cbdcdba500a46c757a Mon Sep 17 00:00:00 2001 From: Tobias Lundin Date: Sat, 19 Nov 2022 22:52:04 +0100 Subject: [PATCH 7/7] try try again --- test/utils.test.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/test/utils.test.js b/test/utils.test.js index c0d167b..54b4fa2 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -5,15 +5,19 @@ import pkgJson from '../package.json' assert { type: 'json' }; import { dirname, join, resolve } from 'path'; import { homedir } from 'os'; +const cliPath = resolve(join(dirname(new URL(import.meta.url).pathname), '../cli.js')); + describe('--dryRun', () => { it('more of a debug print session for CI', async () => { - const cliPathAbs = resolve('../cli.js'); - const cmd = `node ${cliPathAbs} --dryRun`; + + const cmd = `node ${cliPath} --dryRun`; console.log('PLEASE READ THIS', { cwd: process.cwd(), - cmd, + cliPath, + importURL: import.meta.url, filePathURL: new URL('..cli.js', import.meta.url).toString(), filePathResolve: resolve('../cli.js'), + resolveJoinDirname: resolve(join(dirname(import.meta.url), '../cli.js')), }); const { stdout } = await exec(cmd, { cwd: homedir(), env: { ...process.env } }); console.log(` @@ -36,15 +40,14 @@ describe.skip('pkgJson', () => { }); it('cli.js --version, also works from random directory', async () => { - const cliPathAbs = getAbsolutePath('../cli.js', import.meta.url); - const cmd = `node ${cliPathAbs} --version`; + const cmd = `node ${cliPath} --version`; const { stdout } = await exec(cmd, { cwd: homedir(), env: { ...process.env } }); assert.equal(pkgVersion, `${stdout.trim()}`); }); }); const testCertFolder = 'tstCertFolder'; -const cmd = `node ${join(dirname(import.meta.url), '../cli.js').replace(/^file:/, '')}`; +const cmd = `node ${cliPath}`; const rmTestDir = async () => await exec(`rm -rf ${testCertFolder}`, {}); describe.skip('cli', () => {