Skip to content

Commit c2c8cf1

Browse files
committed
fix: cover copy functionality with tests
1 parent b3c06ea commit c2c8cf1

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

src/commands/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ async function copyToDist(cwd: string, files: string[], distDir: string) {
430430
allFiles.map(async (file) => {
431431
if (await fse.pathExists(join(cwd, file))) {
432432
const sourcePath = join(cwd, file);
433-
const destPath = join(cwd, distDir, file.replace("src/", ""));
433+
const destPath = join(distDir, file.replace("src/", ""));
434434
await mkdirp(dirname(destPath));
435435
await fse.copyFile(sourcePath, destPath);
436436
}

test/__fixtures__/simple/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello!

test/__fixtures__/simple/foo.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "hi": 1 }

test/__fixtures__/simple/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,10 @@
4141
"directory": "dist",
4242
"access": "public"
4343
},
44-
"type": "module"
45-
}
44+
"type": "module",
45+
"buildOptions": {
46+
"copy": [
47+
"foo.json"
48+
]
49+
}
50+
}

test/integration.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ it("can bundle a simple project", async () => {
1818
const indexDtsFilePath = path.resolve(baseDistPath, "typings", "index.d.ts");
1919
const indexMjsFilePath = path.resolve(baseDistPath, "esm", "index.js");
2020
const packageJsonFilePath = path.resolve(baseDistPath, "package.json");
21+
const readmeFilePath = path.resolve(baseDistPath, "README.md");
22+
const fooFilePath = path.resolve(baseDistPath, "foo.json");
2123

2224
expect(fse.readFileSync(indexJsFilePath, "utf8")).toMatchInlineSnapshot(`
2325
"\\"use strict\\";
@@ -34,6 +36,14 @@ it("can bundle a simple project", async () => {
3436
"export var someNumber = 1;
3537
"
3638
`);
39+
expect(fse.readFileSync(readmeFilePath, "utf8")).toMatchInlineSnapshot(`
40+
"Hello!
41+
"
42+
`);
43+
expect(fse.readFileSync(fooFilePath, "utf8")).toMatchInlineSnapshot(`
44+
"{ \\"hi\\": 1 }
45+
"
46+
`);
3747
expect(fse.readFileSync(packageJsonFilePath, "utf8")).toMatchInlineSnapshot(`
3848
"{
3949
\\"name\\": \\"simple\\",
@@ -77,6 +87,9 @@ it("can bundle a simple project", async () => {
7787
}
7888
}"
7989
`);
90+
await execa("node", [binaryFolder, "check"], {
91+
cwd: path.resolve(fixturesFolder, "simple")
92+
});
8093
});
8194

8295
it("can build a monorepo project", async () => {
@@ -275,4 +288,8 @@ it("can build a monorepo project", async () => {
275288
}
276289
}"
277290
`);
291+
292+
await execa("node", [binaryFolder, "check"], {
293+
cwd: path.resolve(fixturesFolder, "simple-monorepo")
294+
});
278295
});

0 commit comments

Comments
 (0)