Skip to content

Commit 904a774

Browse files
committed
test: create integration test for minimal libraries
1 parent f245f6f commit 904a774

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import {
2+
ensureNxProject,
3+
runNxCommand,
4+
runPackageManagerInstall,
5+
uniq,
6+
} from '@nx/plugin/testing';
7+
import { initNgxDeployNPMProject, basicSetTestForLibs } from '../utils';
8+
import * as fs from 'fs';
9+
10+
describe('Minimal Project', () => {
11+
const setup = async () => {
12+
ensureNxProject('ngx-deploy-npm', 'dist/packages/ngx-deploy-npm');
13+
runPackageManagerInstall();
14+
15+
const uniqLibName = uniq('minimal-lib');
16+
17+
const { libRoot } = await createMinimalLib(uniqLibName);
18+
19+
// Install the project
20+
runNxCommand(
21+
`generate ngx-deploy-npm:install --project="${uniqLibName}" --dist-folder-path="${libRoot}"`
22+
);
23+
24+
async function createMinimalLib(libName: string) {
25+
// Create Lib
26+
const libRoot = `libs/${libName}`;
27+
const libRootAbsolutePath = `./tmp/nx-e2e/proj/${libRoot}`;
28+
const createRootPromise = fs.promises.mkdir(libRootAbsolutePath, {
29+
recursive: true,
30+
});
31+
const createProjectJsonPromise = fs.promises.writeFile(
32+
`${libRootAbsolutePath}/project.json`,
33+
generateProjectJSON(libName),
34+
'utf8'
35+
);
36+
const createPackageJsonPromise = fs.promises.writeFile(
37+
`${libRootAbsolutePath}/package.json`,
38+
generatePackageJSON(libName),
39+
'utf8'
40+
);
41+
const createUniqueFilePromise = fs.promises.writeFile(
42+
`${libRootAbsolutePath}/hello-world.js`,
43+
"console.log('Hello World!');",
44+
'utf8'
45+
);
46+
await Promise.all([
47+
createRootPromise,
48+
createProjectJsonPromise,
49+
createPackageJsonPromise,
50+
createUniqueFilePromise,
51+
]);
52+
53+
return { libRoot };
54+
55+
function generateProjectJSON(projectName: string): string {
56+
const content = {
57+
name: projectName,
58+
$schema: '../../node_modules/nx/schemas/project-schema.json',
59+
projectType: 'library',
60+
};
61+
62+
return JSON.stringify(content, null, 2);
63+
}
64+
65+
function generatePackageJSON(projectName: string): string {
66+
const content = {
67+
name: `@mock-domain/${projectName}`,
68+
description: 'Minimal LIb',
69+
version: '1.0.0',
70+
};
71+
72+
return JSON.stringify(content, null, 2);
73+
}
74+
}
75+
76+
return {
77+
libRoot,
78+
uniqLibName,
79+
};
80+
};
81+
82+
it('should publish the lib', async () => {
83+
const { uniqLibName } = await setup();
84+
85+
expect(() => {
86+
runNxCommand(`deploy ${uniqLibName} --dry-run`);
87+
}).not.toThrow();
88+
}, 120000);
89+
});

0 commit comments

Comments
 (0)