Skip to content

Commit

Permalink
Failing test for duplicate values in deep arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
erikpukinskis committed Dec 10, 2024
1 parent 442c27e commit b98d6cc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
30 changes: 30 additions & 0 deletions lib/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,36 @@ import { MockSystem } from "~/system"
import { parseAccessor, runCommand } from "./commands"

Check failure on line 4 in lib/commands.test.ts

View workflow job for this annotation

GitHub Actions / check

`./commands` import should occur before import of `~/project`

describe("file command", () => {
it.only("doesn't add the same string to an array twice", async () => {
const system = new MockSystem()

await runCommand(
{
command: "file",
path: ".eslintrc",
contents: {
plugins: ["import"],
},
},
system
)

expect(system.json(".eslintrc").plugins).toHaveLength(1)

await runCommand(
{
command: "file",
path: ".eslintrc",
contents: {
plugins: ["import"],
},
},
system
)

expect(system.json(".eslintrc").plugins).toHaveLength(1)
})

it("parses the query out of an accessor", () => {
expect(parseAccessor("tasks[label=TypeScript Watch]")).toMatchObject({
base: "tasks",
Expand Down
5 changes: 5 additions & 0 deletions lib/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,16 @@ export class MockSystem implements System {
return Boolean(this.contentsByPath[path])
}
read(path: string) {
if (this.contentsByPath[path] === undefined) {
throw new Error(`MockSystem never wrote to path ${path}`)
}
return this.contentsByPath[path]
}
json(path: string) {
const contents = this.read(path)

let json: unknown

try {
json = JSON.parse(contents)
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "confgen",
"version": "0.94.0-beta.1",
"version": "0.94.0-beta.2",
"license": "MIT",
"repository": {
"type": "git",
Expand Down

0 comments on commit b98d6cc

Please sign in to comment.