From 22c0aea623097de5c3b80848e7aa9d1c0b35d093 Mon Sep 17 00:00:00 2001 From: Bryan MacFarlane Date: Sat, 2 May 2020 11:06:05 -0400 Subject: [PATCH] cya snapshot --- __tests__/__snapshots__/authutil.test.ts.snap | 31 ----------------- __tests__/authutil.test.ts | 34 +++++++++++++++---- 2 files changed, 28 insertions(+), 37 deletions(-) delete mode 100644 __tests__/__snapshots__/authutil.test.ts.snap diff --git a/__tests__/__snapshots__/authutil.test.ts.snap b/__tests__/__snapshots__/authutil.test.ts.snap deleted file mode 100644 index 14bee8a..0000000 --- a/__tests__/__snapshots__/authutil.test.ts.snap +++ /dev/null @@ -1,31 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`authutil tests Appends trailing slash to registry 1`] = ` -"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN} -registry=https://registry.npmjs.org/ -always-auth=false" -`; - -exports[`authutil tests Automatically configures GPR scope 1`] = ` -"npm.pkg.github.com/:_authToken=\${NODE_AUTH_TOKEN} -@ownername:registry=npm.pkg.github.com/ -always-auth=false" -`; - -exports[`authutil tests Configures scoped npm registries 1`] = ` -"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN} -@myscope:registry=https://registry.npmjs.org/ -always-auth=false" -`; - -exports[`authutil tests Sets up npmrc for always-auth true 1`] = ` -"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN} -registry=https://registry.npmjs.org/ -always-auth=true" -`; - -exports[`authutil tests Sets up npmrc for npmjs 1`] = ` -"//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN} -registry=https://registry.npmjs.org/ -always-auth=false" -`; diff --git a/__tests__/authutil.test.ts b/__tests__/authutil.test.ts index 94df21b..13f262c 100644 --- a/__tests__/authutil.test.ts +++ b/__tests__/authutil.test.ts @@ -1,3 +1,4 @@ +import os = require('os'); import * as fs from 'fs'; import * as path from 'path'; import * as core from '@actions/core'; @@ -62,20 +63,35 @@ describe('authutil tests', () => { } }, 100000); + function readRcFile(rcFile: string) { + let rc = {}; + let contents = fs.readFileSync(rcFile, {encoding: 'utf8'}); + for (const line of contents.split(os.EOL)) { + let parts = line.split('='); + if (parts.length == 2) { + rc[parts[0].trim()] = parts[1].trim(); + } + } + return rc; + } + it('Sets up npmrc for npmjs', async () => { await auth.configAuthentication('https://registry.npmjs.org/', 'false'); expect(fs.statSync(rcFile)).toBeDefined(); let contents = fs.readFileSync(rcFile, {encoding: 'utf8'}); - dbg(contents); - expect(contents).toMatchSnapshot(); + let rc = readRcFile(rcFile); + expect(rc["registry"]).toBe("https://registry.npmjs.org/"); + expect(rc["always-auth"]).toBe("false"); }); it('Appends trailing slash to registry', async () => { await auth.configAuthentication('https://registry.npmjs.org', 'false'); expect(fs.statSync(rcFile)).toBeDefined(); - expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot(); + let rc = readRcFile(rcFile); + expect(rc["registry"]).toBe("https://registry.npmjs.org/"); + expect(rc["always-auth"]).toBe("false"); }); it('Configures scoped npm registries', async () => { @@ -83,19 +99,25 @@ describe('authutil tests', () => { await auth.configAuthentication('https://registry.npmjs.org', 'false'); expect(fs.statSync(rcFile)).toBeDefined(); - expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot(); + let rc = readRcFile(rcFile); + expect(rc["@myscope:registry"]).toBe("https://registry.npmjs.org/"); + expect(rc["always-auth"]).toBe("false"); }); it('Automatically configures GPR scope', async () => { await auth.configAuthentication('npm.pkg.github.com', 'false'); expect(fs.statSync(rcFile)).toBeDefined(); - expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot(); + let rc = readRcFile(rcFile); + expect(rc["@ownername:registry"]).toBe("npm.pkg.github.com/"); + expect(rc["always-auth"]).toBe("false"); }); it('Sets up npmrc for always-auth true', async () => { await auth.configAuthentication('https://registry.npmjs.org/', 'true'); expect(fs.statSync(rcFile)).toBeDefined(); - expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot(); + let rc = readRcFile(rcFile); + expect(rc["registry"]).toBe("https://registry.npmjs.org/"); + expect(rc["always-auth"]).toBe("true"); }); });