Skip to content

Commit

Permalink
fix: do not trim EOF on the last line of file
Browse files Browse the repository at this point in the history
  • Loading branch information
hasundue committed Nov 10, 2023
1 parent a725188 commit bc3c5fe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
1 change: 0 additions & 1 deletion lib/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ async function writeToModule(
await Deno.writeTextFile(
new URL(update.specifier),
content
.trimEnd()
.split(eol)
.map((line, index) => {
const dependency = lineToDependencyMap.get(index);
Expand Down
31 changes: 14 additions & 17 deletions lib/git_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
afterAll,
assertSpyCalls,
beforeAll,
beforeEach,
Expand All @@ -13,33 +12,29 @@ import {
FileSystemFake,
ReadTextFileStub,
WriteTextFileStub,
LatestSemVerStub,
} from "./testing.ts";
import { URI } from "./uri.ts";
import { SemVerString } from "./semver.ts";
import { DependencyUpdate } from "./update.ts";
import { commitAll } from "./git.ts";

describe("commitAll()", () => {
let updates: DependencyUpdate[];
let fileSystemFake: FileSystemFake;
let writeTextFileStub: WriteTextFileStub;
let readTextFileStub: ReadTextFileStub;
let CommandStub: ReturnType<typeof createCommandStub>;
const LATEST = "123.456.789" as SemVerString;

beforeAll(async () => {
LatestSemVerStub.create(LATEST);
updates = await DependencyUpdate.collect(
"./test/fixtures/direct-import/mod.ts",
);
fileSystemFake = new FileSystemFake();
readTextFileStub = ReadTextFileStub.create(fileSystemFake, {
ReadTextFileStub.create(fileSystemFake, {
readThrough: true,
});
writeTextFileStub = WriteTextFileStub.create(fileSystemFake);
});

afterAll(() => {
writeTextFileStub.restore();
readTextFileStub.restore();
Deno.Command = CommandStub.original;
WriteTextFileStub.create(fileSystemFake);
});

beforeEach(() => {
Expand All @@ -49,12 +44,14 @@ describe("commitAll()", () => {
});

const expected = [
`import { assertEquals } from "https://deno.land/std@0.205.0/assert/assert_equals.ts";
import { createGraph } from "https://deno.land/x/deno_graph@0.59.2/mod.ts";
import emoji from "npm:node-emoji@2.1.0";
import { noop } from "./lib.ts";`,
`import { assertExists } from "https://deno.land/std@0.205.0/assert/assert_exists.ts";
export const noop = () => {};`,
`import { assertEquals } from "https://deno.land/std@${LATEST}/assert/assert_equals.ts";
import { createGraph } from "https://deno.land/x/deno_graph@${LATEST}/mod.ts";
import emoji from "npm:node-emoji@${LATEST}";
import { noop } from "./lib.ts";
`,
`import { assertExists } from "https://deno.land/std@${LATEST}/assert/assert_exists.ts";
export const noop = () => {};
`,
];

// "git add src/fixtures/mod.ts src/fixtures/lib.ts",
Expand Down
20 changes: 14 additions & 6 deletions test/snapshots/file_test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ snapshot[`FileUpdate.write() > direct import 1`] = `
'import { assertEquals } from "https://deno.land/std@123.456.789/assert/assert_equals.ts";
import { createGraph } from "https://deno.land/x/deno_graph@123.456.789/mod.ts";
import emoji from "npm:node-emoji@123.456.789";
import { noop } from "./lib.ts";'
import { noop } from "./lib.ts";
'
`;

snapshot[`FileUpdate.write() > direct import 2`] = `
'import { assertExists } from "https://deno.land/std@123.456.789/assert/assert_exists.ts";
export const noop = () => {};'
export const noop = () => {};
'
`;

snapshot[`FileUpdate.write() > import map 1`] = `
Expand All @@ -25,19 +27,25 @@ snapshot[`FileUpdate.write() > import map 1`] = `

snapshot[`FileUpdate.write() > import map 2`] = `
'import { VERSION } from "https://deno.land/std@123.456.789/version.ts";
export const noop = () => {};'
export const noop = () => {};
'
`;

snapshot[`FileUpdate.write() > import map with no resolve 1`] = `'import {} from "https://deno.land/std@123.456.789/testing/asserts.ts";'`;
snapshot[`FileUpdate.write() > import map with no resolve 1`] = `
'import {} from "https://deno.land/std@123.456.789/testing/asserts.ts";
'
`;

snapshot[`FileUpdate.write() > unversioned specifiers 1`] = `
'import { VERSION } from "https://deno.land/std@123.456.789";
import { createGraph } from "https://deno.land/x/deno_graph@123.456.789/mod.ts";
import { emojify } from "npm:node-emoji@123.456.789";
import { noop } from "./lib.ts";'
import { noop } from "./lib.ts";
'
`;

snapshot[`FileUpdate.write() > unversioned specifiers 2`] = `
'import { VERSION } from "https://deno.land/std@123.456.789/version.ts";
export const noop = () => {};'
export const noop = () => {};
'
`;

0 comments on commit bc3c5fe

Please sign in to comment.