Skip to content

Commit 79ba92d

Browse files
committed
test: migrate the rest of the test
1 parent 271f6e4 commit 79ba92d

File tree

9 files changed

+142
-24
lines changed

9 files changed

+142
-24
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { TargetConfiguration } from '@nx/devkit';
2+
import { uniq } from '@nx/plugin/testing';
3+
4+
import { DeployExecutorOptions } from 'bikecoders/ngx-deploy-npm';
5+
import { npmAccess } from 'bikecoders/ngx-deploy-npm';
6+
import { setup } from './utils';
7+
8+
describe('install', () => {
9+
const expectedTarget = ({
10+
projectName,
11+
isBuildable = true,
12+
access = npmAccess.public,
13+
customDistFolderPath,
14+
}: {
15+
projectName: string;
16+
isBuildable?: boolean;
17+
access?: npmAccess;
18+
customDistFolderPath?: string;
19+
}): TargetConfiguration<DeployExecutorOptions> => {
20+
const target: TargetConfiguration<DeployExecutorOptions> = {
21+
executor: 'ngx-deploy-npm:deploy',
22+
options: {
23+
distFolderPath: customDistFolderPath || `dist/packages/${projectName}`,
24+
access,
25+
},
26+
};
27+
28+
if (isBuildable) {
29+
target.dependsOn = ['build'];
30+
}
31+
32+
return target;
33+
};
34+
35+
it('should modify the workspace only for the indicated libs', async () => {
36+
const { processedLibs, tearDown } = await setup([
37+
{ name: uniq('node-lib1'), generator: '@nx/node' },
38+
{ name: uniq('node-lib2'), generator: '@nx/node' },
39+
{
40+
name: uniq('node-resctricted'),
41+
installOptions: {
42+
access: npmAccess.restricted,
43+
},
44+
generator: '@nx/node',
45+
},
46+
{
47+
name: uniq('node-lib-not-set'),
48+
skipInstall: true,
49+
generator: '@nx/node',
50+
},
51+
{ name: uniq('small-lib'), generator: 'minimal' },
52+
]);
53+
const [publicLib, publicLib2, restrictedLib, libNOTSet, smallLib] =
54+
processedLibs;
55+
56+
expect(publicLib.workspace.targets?.deploy).toEqual(
57+
expectedTarget({ projectName: publicLib.name })
58+
);
59+
expect(publicLib2.workspace.targets?.deploy).toEqual(
60+
expectedTarget({ projectName: publicLib2.name })
61+
);
62+
expect(restrictedLib.workspace.targets?.deploy).toEqual(
63+
expectedTarget({
64+
projectName: restrictedLib.name,
65+
access: npmAccess.restricted,
66+
})
67+
);
68+
expect(libNOTSet.workspace.targets?.deploy).toEqual(undefined);
69+
70+
expect(smallLib.workspace.targets?.deploy).toEqual(
71+
expectedTarget({
72+
projectName: smallLib.name,
73+
customDistFolderPath: smallLib.workspace.sourceRoot,
74+
isBuildable: false,
75+
})
76+
);
77+
78+
return tearDown();
79+
}, 120000);
80+
});

packages/ngx-deploy-npm-e2e/src/publish-minimal-lib.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ describe('Minimal Project', () => {
99
const [uniqLibName] = processedLibs;
1010

1111
executeCommand(
12-
`npx nx deploy ${uniqLibName.name} --tag e2e --registry=http://localhost:4873`
12+
`npx nx deploy ${uniqLibName.name} --tag="e2e" --registry=http://localhost:4873 --packageVersion=0.0.0`
1313
);
1414

1515
expect(() => {
16+
executeCommand(`npm view ${uniqLibName.npmPackageName}@0.0.0`);
1617
executeCommand(`npm view ${uniqLibName.npmPackageName}@e2e`);
1718
}).not.toThrow();
1819

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { uniq } from '@nx/plugin/testing';
2+
import { setup } from './utils';
3+
4+
describe('Publish', () => {
5+
test.each([
6+
{
7+
name: uniq('angular-lib'),
8+
generator: '@nx/angular',
9+
extraOptions: '--style css',
10+
},
11+
{
12+
name: uniq('node-lib'),
13+
generator: '@nx/node',
14+
},
15+
])(
16+
'should publish with $generator lib',
17+
async libConfig => {
18+
const { executeCommand, tearDown, processedLibs } = await setup([
19+
libConfig,
20+
]);
21+
const [lib] = processedLibs;
22+
23+
executeCommand(
24+
`npx nx deploy ${lib.name} --registry=http://localhost:4873 --tag="e2e" --packageVersion=0.0.0`
25+
);
26+
27+
expect(() => {
28+
executeCommand(`npm view ${lib.npmPackageName}@0.0.0`);
29+
executeCommand(`npm view ${lib.npmPackageName}@e2e`);
30+
}).not.toThrow();
31+
32+
return tearDown();
33+
},
34+
120000 * 2
35+
);
36+
});

packages/ngx-deploy-npm-e2e/src/utils/basic-setup.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
installNgxDeployNPMProject,
1515
} from '.';
1616

17-
const mockDomian = '@mock-domain';
17+
const buildPackageProjectRoot = (libName: string) => `packages/${libName}`;
1818

1919
const executeCommandFactory =
2020
(projectDirectory: string) => (command: string) => {
@@ -76,7 +76,9 @@ export const setup = async (
7676
nxPlugin: generator,
7777
executeCommand,
7878
libName: name,
79-
extraOptions: `--directory="libs/${name}" ${extraOptions}`,
79+
extraOptions: `--directory="${buildPackageProjectRoot(
80+
name
81+
)}" ${extraOptions}`,
8082
});
8183
}
8284
})
@@ -99,8 +101,8 @@ export const setup = async (
99101

100102
const distFolderPath =
101103
generator === 'minimal'
102-
? getMinimalLibRoot(projectDirectory, name).libRoot
103-
: `dist/libs/${name}`;
104+
? buildPackageProjectRoot(name)
105+
: `dist/${buildPackageProjectRoot(name)}`;
104106

105107
installNgxDeployNPMProject(
106108
executeCommand,
@@ -114,8 +116,12 @@ export const setup = async (
114116
npmPackageName: string;
115117
}[] = libs.map(({ name }) => ({
116118
name: name,
117-
workspace: readJson(`${projectDirectory}/packages/${name}/project.json`),
118-
npmPackageName: `${mockDomian}/${name}`,
119+
workspace: readJson(
120+
`${projectDirectory}/${buildPackageProjectRoot(name)}/project.json`
121+
),
122+
npmPackageName: readJson(
123+
`${projectDirectory}/${buildPackageProjectRoot(name)}/package.json`
124+
).name,
119125
}));
120126

121127
return {
@@ -133,19 +139,13 @@ export const setup = async (
133139
};
134140
};
135141

136-
function getMinimalLibRoot(projectDirectory: string, libName: string) {
137-
const libRoot = `packages/${libName}`;
138-
const libRootAbsolutePath = join(projectDirectory, libRoot);
139-
140-
return { libRoot, libRootAbsolutePath };
141-
}
142-
143142
async function createMinimalLib(projectDirectory: string, libName: string) {
144143
// Create Lib
145-
const { libRoot, libRootAbsolutePath } = getMinimalLibRoot(
144+
const libRootAbsolutePath = join(
146145
projectDirectory,
147-
libName
146+
buildPackageProjectRoot(libName)
148147
);
148+
const libRoot = buildPackageProjectRoot(libName);
149149

150150
// Create the lib folder
151151
await fs.promises.mkdir(libRootAbsolutePath, {
@@ -188,7 +188,7 @@ async function createMinimalLib(projectDirectory: string, libName: string) {
188188

189189
function generatePackageJSON(projectName: string): string {
190190
const content = {
191-
name: `${mockDomian}/${projectName}`,
191+
name: `@mock-domain/${projectName}`,
192192
description: 'Minimal LIb',
193193
version: '1.0.0',
194194
};
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
import packageJson from '../../../../package.json'; // This import style requires "esModuleInterop", see "side notes"
1+
import { readJson } from '@nx/plugin/testing';
22

3-
export const currentNxVersion = packageJson.devDependencies['@nx/workspace'];
3+
export const currentNxVersion = readJson(`${process.cwd()}/package.json`)
4+
.devDependencies['@nx/workspace'];

packages/ngx-deploy-npm-e2e/tsconfig.spec.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
"compilerOptions": {
44
"outDir": "../../dist/out-tsc",
55
"module": "commonjs",
6-
"types": ["jest", "node"],
7-
"resolveJsonModule": true,
8-
"esModuleInterop": true
6+
"types": ["jest", "node"]
97
},
108
"include": [
119
"jest.config.ts",

packages/ngx-deploy-npm/src/__mocks__/mocks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const getLib = (libName: string): ProjectConfiguration => {
1212
executor: '@mocks/compiler:rollup',
1313
outputs: ['{options.outputPath}'],
1414
options: {
15-
outputPath: `dist/libs/${libName}`,
15+
outputPath: `dist/packages/${libName}`,
1616
},
1717
},
1818
...mockLintTarget,

packages/ngx-deploy-npm/src/executors/deploy/actions.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('Deploy', () => {
3131
it('should invoke the engine', async () => {
3232
const { mockEngine, context } = setup();
3333
const options: DeployExecutorOptions = {
34-
distFolderPath: 'dist/libs/project',
34+
distFolderPath: 'dist/packages/project',
3535
access: 'public',
3636
};
3737

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
export type { InstallGeneratorOptions } from './generators/install/schema';
2+
export type { DeployExecutorOptions } from './executors/deploy/schema';
3+
export { npmAccess } from './core/npm-access.enum';

0 commit comments

Comments
 (0)