-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: merge local bunfig with action scope/registry config
- Loading branch information
1 parent
830e319
commit 8c0b797
Showing
8 changed files
with
201 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ on: | |
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
jobs: | ||
setup-bun: | ||
runs-on: ${{ matrix.os }} | ||
|
@@ -25,17 +26,21 @@ jobs: | |
- id: checkout | ||
name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- id: setup-bun | ||
name: Setup Bun | ||
uses: ./ | ||
with: | ||
bun-version: ${{ matrix.bun-version }} | ||
|
||
- id: verify-bun | ||
name: Verify Bun | ||
run: | | ||
bun --version | ||
setup-bun-from-package-json-version: | ||
runs-on: ${{ matrix.os }} | ||
needs: setup-bun | ||
strategy: | ||
matrix: | ||
os: | ||
|
@@ -44,11 +49,26 @@ jobs: | |
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup package.json | ||
run: | | ||
echo "$(jq '. += {"packageManager": "[email protected]"}' package.json)" > package.json | ||
- name: Setup Bun | ||
uses: ./ | ||
|
||
- name: Verify Bun | ||
run: | | ||
bun --version | ||
tests: | ||
name: Run tests | ||
needs: setup-bun | ||
runs-on: 'ubuntu-latest' | ||
|
||
steps: | ||
- name: Setup Bun | ||
uses: ./ | ||
|
||
- name: Run tests | ||
run: bun test --coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import { afterEach, describe, expect, it } from "bun:test"; | ||
import { unlink } from "fs"; | ||
import { configureAuthentication } from "./auth"; | ||
import { EOL } from "os"; | ||
|
||
describe("#configureAuthentication", () => { | ||
const filePath = "bunfig.toml"; | ||
|
||
async function getFileAndContents() { | ||
const file = Bun.file(filePath); | ||
const contents = (await file.text()).split(EOL); | ||
|
||
return { file, contents }; | ||
} | ||
|
||
afterEach(() => { | ||
unlink(filePath, () => console.log(`${filePath} was deleted`)); | ||
}); | ||
|
||
describe("when no bunfig.toml file exists", () => { | ||
it("should create a new file with scopes content", async () => { | ||
configureAuthentication("https://npm.pkg.github.com", "foo-bar"); | ||
|
||
const { file, contents } = await getFileAndContents(); | ||
|
||
expect(file.exists()).resolves.toBeTrue(); | ||
|
||
const expectedContents = [ | ||
"[install.scopes]", | ||
"", | ||
'\'@foo-bar\' = { token = "$BUN_AUTH_TOKEN", url = "https://npm.pkg.github.com/" }', | ||
"", | ||
]; | ||
|
||
contents.forEach((content, index) => | ||
expect(content).toBe(expectedContents[index]) | ||
); | ||
|
||
expect(contents.length).toBe(expectedContents.length); | ||
}); | ||
}); | ||
|
||
describe("when local bunfig.toml file exists", () => { | ||
it("and no [install.scopes] exists, should concatenate file correctly", async () => { | ||
const bunfig = `[install]${EOL}optional = true${EOL}${EOL}[install.cache]${EOL}disable = true`; | ||
|
||
await Bun.write(filePath, bunfig); | ||
|
||
configureAuthentication("https://npm.pkg.github.com/", "foo-bar"); | ||
|
||
const { file, contents } = await getFileAndContents(); | ||
|
||
expect(file.exists()).resolves.toBeTrue(); | ||
|
||
const expectedContents = [ | ||
"[install]", | ||
"optional = true", | ||
"", | ||
"[install.cache]", | ||
"disable = true", | ||
"[install.scopes]", | ||
"", | ||
'\'@foo-bar\' = { token = "$BUN_AUTH_TOKEN", url = "https://npm.pkg.github.com/" }', | ||
"", | ||
"", | ||
]; | ||
|
||
contents.forEach((content, index) => | ||
expect(content).toBe(expectedContents[index]) | ||
); | ||
|
||
expect(contents.length).toBe(expectedContents.length); | ||
}); | ||
|
||
it("and [install.scopes] exists and it's not the same registry, should concatenate file correctly", async () => { | ||
const bunfig = `[install]${EOL}optional = true${EOL}${EOL}[install.scopes]${EOL}'@bla-ble' = { token = "$BUN_AUTH_TOKEN", url = "https://npm.pkg.github.com/" }${EOL}${EOL}[install.cache]${EOL}disable = true`; | ||
|
||
await Bun.write(filePath, bunfig); | ||
|
||
configureAuthentication("https://npm.pkg.github.com/", "foo-bar"); | ||
|
||
const { file, contents } = await getFileAndContents(); | ||
|
||
expect(file.exists()).resolves.toBeTrue(); | ||
|
||
const expectedContents = [ | ||
"[install]", | ||
"optional = true", | ||
"", | ||
"[install.scopes]", | ||
'\'@foo-bar\' = { token = "$BUN_AUTH_TOKEN", url = "https://npm.pkg.github.com/" }', | ||
'\'@bla-ble\' = { token = "$BUN_AUTH_TOKEN", url = "https://npm.pkg.github.com/" }', | ||
"", | ||
"[install.cache]", | ||
"disable = true", | ||
"", | ||
"", | ||
]; | ||
|
||
contents.forEach((content, index) => | ||
expect(content).toBe(expectedContents[index]) | ||
); | ||
|
||
expect(contents.length).toBe(expectedContents.length); | ||
}); | ||
|
||
it("and [install.scopes] exists and it's the same registry, should concatenate file correctly", async () => { | ||
const bunfig = `[install]${EOL}optional = true${EOL}${EOL}[install.scopes]${EOL}'@foo-bar' = { token = "$BUN_AUTH_TOKEN", url = "https://npm.pkg.github.com/" }${EOL}'@bla-ble' = { token = "$BUN_AUTH_TOKEN", url = "https://npm.pkg.github.com/" }${EOL}${EOL}[install.cache]${EOL}disable = true`; | ||
|
||
await Bun.write(filePath, bunfig); | ||
|
||
configureAuthentication("https://npm.pkg.github.com/", "foo-bar"); | ||
|
||
const { file, contents } = await getFileAndContents(); | ||
|
||
expect(file.exists()).resolves.toBeTrue(); | ||
|
||
const expectedContents = [ | ||
"[install]", | ||
"optional = true", | ||
"", | ||
"[install.scopes]", | ||
'\'@foo-bar\' = { token = "$BUN_AUTH_TOKEN", url = "https://npm.pkg.github.com/" }', | ||
'\'@bla-ble\' = { token = "$BUN_AUTH_TOKEN", url = "https://npm.pkg.github.com/" }', | ||
"", | ||
"[install.cache]", | ||
"disable = true", | ||
"", | ||
"", | ||
]; | ||
|
||
contents.forEach((content, index) => | ||
expect(content).toBe(expectedContents[index]) | ||
); | ||
|
||
expect(contents.length).toBe(expectedContents.length); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters