Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Fixes tests
  • Loading branch information
arcanis committed Mar 23, 2022
commit aaaca2785c9a12b565759f56d90b8dca4758842a
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Manifest} from '@yarnpkg/core';
import {PortablePath} from '@yarnpkg/fslib';
import {merge} from 'lodash';
import {fs, yarn} from 'pkg-tests-core';
import {Manifest} from '@yarnpkg/core';
import {Filename, PortablePath, ppath, xfs} from '@yarnpkg/fslib';
import {merge} from 'lodash';
import {fs, yarn} from 'pkg-tests-core';

const {unpackToDirectory} = fs;
const {writeConfiguration, readManifest} = yarn;
Expand All @@ -10,9 +10,45 @@ describe(`Plugins`, () => {
describe(`typescript`, () => {
describe(`Adding types`, () => {
test(
`it should automatically add @types to devDependencies when package doesn't provide types`,
`it shouldn't be enabled by default`,
makeTemporaryEnv({}, async ({path, run, source}) => {
await run(`add`, `is-number`);

const manifestPromise = readManifest(path);

await expect(manifestPromise).resolves.toMatchObject({
dependencies: {
[`is-number`]: `^2.0.0`,
},
});

await expect(manifestPromise).not.toHaveProperty(`devDependencies`);
}),
);

test(
`it should automatically enable automatic @types insertion when a tsconfig is detected`,
makeTemporaryEnv({}, async ({path, run, source}) => {
await writeConfiguration(path, {plugins: [require.resolve(`@yarnpkg/monorepo/scripts/plugin-typescript.js`)]});
await xfs.writeFilePromise(ppath.join(path, `tsconfig.json` as Filename), ``);

await run(`add`, `is-number`);

await expect(readManifest(path)).resolves.toMatchObject({
dependencies: {
[`is-number`]: `^2.0.0`,
},
devDependencies: {
[`@types/is-number`]: `^2`,
},
});
}),
);

test(
`it should automatically add @types to devDependencies when package doesn't provide types`,
makeTemporaryEnv({}, {
tsEnableAutoTypes: true,
}, async ({path, run, source}) => {
await run(`add`, `is-number`);

await expect(readManifest(path)).resolves.toMatchObject({
Expand All @@ -28,8 +64,9 @@ describe(`Plugins`, () => {

test(
`it should not add @types when package provides its own types`,
makeTemporaryEnv({}, async ({path, run, source}) => {
await writeConfiguration(path, {plugins: [require.resolve(`@yarnpkg/monorepo/scripts/plugin-typescript.js`)]});
makeTemporaryEnv({}, {
tsEnableAutoTypes: true,
}, async ({path, run, source}) => {
await run(`add`, `left-pad`);

await expect(readManifest(path)).resolves.toMatchObject({
Expand All @@ -42,8 +79,9 @@ describe(`Plugins`, () => {

test(
`it should automatically add @types for scoped packages`,
makeTemporaryEnv({}, async ({path, run, source}) => {
await writeConfiguration(path, {plugins: [require.resolve(`@yarnpkg/monorepo/scripts/plugin-typescript.js`)]});
makeTemporaryEnv({}, {
tsEnableAutoTypes: true,
}, async ({path, run, source}) => {
await run(`add`, `@iarna/toml`);

await expect(readManifest(path)).resolves.toMatchObject({
Expand All @@ -59,8 +97,9 @@ describe(`Plugins`, () => {

test(
`it should not generate a @types dependency if @types package doesn't exist`,
makeTemporaryEnv({}, async ({path, run, source}) => {
await writeConfiguration(path, {plugins: [require.resolve(`@yarnpkg/monorepo/scripts/plugin-typescript.js`)]});
makeTemporaryEnv({}, {
tsEnableAutoTypes: true,
}, async ({path, run, source}) => {
await run(`add`, `resolve`);

await expect(readManifest(path)).resolves.toMatchObject({
Expand All @@ -73,8 +112,9 @@ describe(`Plugins`, () => {

test(
`it should not add @types for transient dependencies`,
makeTemporaryEnv({}, async ({path, run, source}) => {
await writeConfiguration(path, {plugins: [require.resolve(`@yarnpkg/monorepo/scripts/plugin-typescript.js`)]});
makeTemporaryEnv({}, {
tsEnableAutoTypes: true,
}, async ({path, run, source}) => {
await run(`add`, `one-fixed-dep-with-types`);

await expect(readManifest(path)).resolves.toMatchObject({
Expand All @@ -87,8 +127,9 @@ describe(`Plugins`, () => {

test(
`it should add @types with the range '^<original-major>' by default`,
makeTemporaryEnv({}, async ({path, run, source}) => {
await writeConfiguration(path, {plugins: [require.resolve(`@yarnpkg/monorepo/scripts/plugin-typescript.js`)]});
makeTemporaryEnv({}, {
tsEnableAutoTypes: true,
}, async ({path, run, source}) => {
await run(`add`, `is-number@^1.0.0`);

await expect(readManifest(path)).resolves.toMatchObject({
Expand All @@ -115,9 +156,9 @@ describe(`Plugins`, () => {
[`@types/is-number`]: `1.0.0`,
},
},
}, {
tsEnableAutoTypes: true,
}, async ({path, run, source}) => {
await writeConfiguration(path, {plugins: [require.resolve(`@yarnpkg/monorepo/scripts/plugin-typescript.js`)]});

await run(`add`, `is-number@^2.0.0`);

await expect(readManifest(path)).resolves.toMatchObject({
Expand Down Expand Up @@ -147,9 +188,9 @@ describe(`Plugins`, () => {
[`@types/is-number`]: `1.0.0`,
},
},
}, {
tsEnableAutoTypes: true,
}, async ({path, run, source}) => {
await writeConfiguration(path, {plugins: [require.resolve(`@yarnpkg/monorepo/scripts/plugin-typescript.js`)]});

await run(`add`, `is-number@^2.0.0`);

await expect(readManifest(path)).resolves.toMatchObject({
Expand All @@ -176,9 +217,9 @@ describe(`Plugins`, () => {
[`@types/is-number`]: `1.0.0`,
},
},
}, {
tsEnableAutoTypes: true,
}, async ({path, run, source}) => {
await writeConfiguration(path, {plugins: [require.resolve(`@yarnpkg/monorepo/scripts/plugin-typescript.js`)]});

await run(`add`, `is-number@^2.0.0`);

await expect(readManifest(path)).resolves.toMatchObject({
Expand All @@ -202,9 +243,9 @@ describe(`Plugins`, () => {
[`is-number`]: `^1.0.0`,
},
},
}, {
tsEnableAutoTypes: true,
}, async ({path, run, source}) => {
await writeConfiguration(path, {plugins: [require.resolve(`@yarnpkg/monorepo/scripts/plugin-typescript.js`)]});

await run(`add`, `is-number@^1.0.0`);

await expect(readManifest(path)).resolves.toMatchObject({
Expand Down Expand Up @@ -236,9 +277,9 @@ describe(`Plugins`, () => {
[`@types/is-number`]: `2.0.0`,
},
},
}, {
tsEnableAutoTypes: true,
}, async ({path, run, source}) => {
await writeConfiguration(path, {plugins: [require.resolve(`@yarnpkg/monorepo/scripts/plugin-typescript.js`)]});

await run(`add`, `is-number@^2.0.0`);

await expect(readManifest(path)).resolves.toMatchObject({
Expand Down Expand Up @@ -266,7 +307,6 @@ describe(`Plugins`, () => {
[`@types/is-number`]: `1.0.0`,
},
}), async ({path, run, source}) => {
await writeConfiguration(path, {plugins: [require.resolve(`@yarnpkg/monorepo/scripts/plugin-typescript.js`)]});
await run(`remove`, `is-number`);

await expect(readManifest(path)).resolves.not.toHaveProperty(`${type}.@types/is-number`);
Expand All @@ -284,7 +324,6 @@ describe(`Plugins`, () => {
[`@types/iarna__toml`]: `1.0.0`,
},
}, async ({path, run, source}) => {
await writeConfiguration(path, {plugins: [require.resolve(`@yarnpkg/monorepo/scripts/plugin-typescript.js`)]});
await run(`remove`, `@iarna/toml`);

await expect(readManifest(path)).resolves.not.toHaveProperty(`devDependencies.@types/iarna__toml`);
Expand All @@ -303,8 +342,6 @@ describe(`Plugins`, () => {
typings: `./published-typings.d.ts`,
},
}, async ({path, run, source}) => {
await writeConfiguration(path, {plugins: [require.resolve(`@yarnpkg/monorepo/scripts/plugin-typescript.js`)]});

await run(`install`);
await run(`pack`);

Expand Down