Skip to content

Commit

Permalink
test: Verify typescript packages with root src/ dir can be build
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Croes committed Sep 27, 2022
1 parent 59a3771 commit f6bc25a
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions packages/cli/src/build/__tests__/src-root.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import build from "../";
import {
testdir,
getDist,
ts,
repoNodeModules,
} from "../../../test-utils";

test("monorepo with root src dir and typescript package", async () => {
let tmpPath = await testdir({
"package.json": JSON.stringify({
name: "root",
devDependencies: {
typescript: "^3.8.3",
},
preconstruct: {
packages: ["src/packages/*"],
},
}),
".babelrc": JSON.stringify({
presets: [
require.resolve("@babel/preset-env"),
require.resolve("@babel/preset-typescript"),
],
}),
node_modules: {
kind: "symlink",
path: repoNodeModules,
},
"src/packages/my-package/package.json": JSON.stringify({
name: "my-package",
main: "dist/my-package.cjs.js",
module: "dist/my-package.esm.js",
}),
"src/packages/my-package/tsconfig.json": `{
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"outDir": "./build"
"isolatedModules": true,
"esModuleInterop": true,
"noEmit": true
}
}
`,

"src/packages/my-package/src/index.ts": ts`
export default {};
`,
});

await build(tmpPath);

expect(await getDist(tmpPath + "/src/packages/my-package")).toMatchInlineSnapshot(`
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ dist/declarations/build/index.d.ts ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
declare const _default: {};
export default _default;
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ dist/my-package.cjs.d.ts ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
export * from "./declarations/build/index";
export { default } from "./declarations/build/index";
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ dist/my-package.cjs.dev.js, dist/my-package.cjs.prod.js ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var index = {};
exports.default = index;
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ dist/my-package.cjs.js ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
'use strict';
if (process.env.NODE_ENV === "production") {
module.exports = require("./my-package.cjs.prod.js");
} else {
module.exports = require("./my-package.cjs.dev.js");
}
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ dist/my-package.esm.js ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
var index = {};
export default index;
`);
});

0 comments on commit f6bc25a

Please sign in to comment.