Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: package.json eol is removed #201

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/fixtures
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"ofetch": "^1.3.4",
"open": "^10.1.0",
"pathe": "^1.1.2",
"pkg-types": "^1.0.3",
"pkg-types": "^1.1.3",
"scule": "^1.3.0",
"semver": "^7.6.0",
"std-env": "^3.7.0",
Expand All @@ -63,4 +63,4 @@
"vitest": "^1.4.0"
},
"packageManager": "[email protected]"
}
}
50 changes: 22 additions & 28 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/fixtures/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"//": "This file must have an empty ending line"
}
43 changes: 43 additions & 0 deletions test/package.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { promises as fsp } from "node:fs";
import { describe, expect, test } from "vitest";
import { readPackageJSON, writePackageJSON } from "../src/package";

describe("package", () => {
const config = {
cwd: "./test/fixtures",
types: {},
scopeMap: {},
tokens: {},
from: "",
to: "",
output: "",
publish: {},
templates: {},
excludeAuthors: [],
};

test("read package.json with trailing newlines", async () => {
const file = await readPackageJSON(config);

expect(file).toMatchInlineSnapshot(`
{
"//": "This file must have an empty ending line",
}
`);
});

test("write package.json with trailing newlines", async () => {
const file = await readPackageJSON(config);

await writePackageJSON(config, file);

const newFile = await fsp.readFile("./test/fixtures/package.json", "utf8");

expect(newFile).toMatchInlineSnapshot(`
"{
"//": "This file must have an empty ending line"
}
"
`);
});
});
15 changes: 10 additions & 5 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { defineConfig } from 'vitest/config'
import { defineConfig } from "vitest/config";

export default defineConfig({
server: {
watch: {
ignored: ["**/test/fixtures/package.json"],
},
},
test: {
coverage: {
reporter: ['text', 'clover', 'json']
}
}
})
reporter: ["text", "clover", "json"],
},
},
});
Loading