Skip to content

Commit

Permalink
fix: cover copy functionality with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ru4l committed Jun 27, 2022
1 parent b3c06ea commit c2c8cf1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ async function copyToDist(cwd: string, files: string[], distDir: string) {
allFiles.map(async (file) => {
if (await fse.pathExists(join(cwd, file))) {
const sourcePath = join(cwd, file);
const destPath = join(cwd, distDir, file.replace("src/", ""));
const destPath = join(distDir, file.replace("src/", ""));
await mkdirp(dirname(destPath));
await fse.copyFile(sourcePath, destPath);
}
Expand Down
1 change: 1 addition & 0 deletions test/__fixtures__/simple/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello!
1 change: 1 addition & 0 deletions test/__fixtures__/simple/foo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "hi": 1 }
9 changes: 7 additions & 2 deletions test/__fixtures__/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,10 @@
"directory": "dist",
"access": "public"
},
"type": "module"
}
"type": "module",
"buildOptions": {
"copy": [
"foo.json"
]
}
}
17 changes: 17 additions & 0 deletions test/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ it("can bundle a simple project", async () => {
const indexDtsFilePath = path.resolve(baseDistPath, "typings", "index.d.ts");
const indexMjsFilePath = path.resolve(baseDistPath, "esm", "index.js");
const packageJsonFilePath = path.resolve(baseDistPath, "package.json");
const readmeFilePath = path.resolve(baseDistPath, "README.md");
const fooFilePath = path.resolve(baseDistPath, "foo.json");

expect(fse.readFileSync(indexJsFilePath, "utf8")).toMatchInlineSnapshot(`
"\\"use strict\\";
Expand All @@ -34,6 +36,14 @@ it("can bundle a simple project", async () => {
"export var someNumber = 1;
"
`);
expect(fse.readFileSync(readmeFilePath, "utf8")).toMatchInlineSnapshot(`
"Hello!
"
`);
expect(fse.readFileSync(fooFilePath, "utf8")).toMatchInlineSnapshot(`
"{ \\"hi\\": 1 }
"
`);
expect(fse.readFileSync(packageJsonFilePath, "utf8")).toMatchInlineSnapshot(`
"{
\\"name\\": \\"simple\\",
Expand Down Expand Up @@ -77,6 +87,9 @@ it("can bundle a simple project", async () => {
}
}"
`);
await execa("node", [binaryFolder, "check"], {
cwd: path.resolve(fixturesFolder, "simple")
});
});

it("can build a monorepo project", async () => {
Expand Down Expand Up @@ -275,4 +288,8 @@ it("can build a monorepo project", async () => {
}
}"
`);

await execa("node", [binaryFolder, "check"], {
cwd: path.resolve(fixturesFolder, "simple-monorepo")
});
});

0 comments on commit c2c8cf1

Please sign in to comment.