Skip to content

Commit

Permalink
chore(repo): revert changes to cnw tests
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Apr 4, 2023
1 parent 3758299 commit 7fc2e8a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 20 deletions.
19 changes: 12 additions & 7 deletions e2e/utils/create-project-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function newProject({

if (!directoryExists(tmpBackupProjPath())) {
runCreateWorkspace(projScope, {
preset: 'apps',
preset: 'empty',
packageManager,
});

Expand Down Expand Up @@ -287,12 +287,17 @@ export function packageInstall(
} ${pkgsWithVersions}${isVerbose() ? ' --verbose' : ''}`;

try {
const install = execSync(command, {
cwd,
stdio: 'pipe',
env: process.env,
encoding: 'utf-8',
});
const install = execSync(
`${mode === 'dev' ? pm.addDev : pm.addProd} ${pkgsWithVersions}${
isVerbose() ? ' --verbose' : ''
}`,
{
cwd,
stdio: 'pipe',
env: process.env,
encoding: 'utf-8',
}
);

if (isVerbose()) {
output.log({
Expand Down
71 changes: 58 additions & 13 deletions e2e/workspace-create/src/create-nx-workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('create-nx-workspace', () => {

afterEach(() => cleanupProject());

it('should create a workspace with a single angular app at the root without routing', () => {
it('should create a workspace with a single angular app at the root with routing', () => {
const wsName = uniq('angular');

runCreateWorkspace(wsName, {
Expand All @@ -28,6 +28,24 @@ describe('create-nx-workspace', () => {
style: 'css',
packageManager,
standaloneApi: false,
routing: true,
});

checkFilesExist('package.json');
checkFilesExist('src/app/app.routes.ts');
checkFilesDoNotExist('tsconfig.base.json');
checkFilesExist('project.json');
expectCodeIsFormatted();
});

it('should create a workspace with a single angular app at the root without routing', () => {
const wsName = uniq('angular');

runCreateWorkspace(wsName, {
preset: 'angular-standalone',
appName: wsName,
style: 'css',
packageManager,
routing: false,
});

Expand All @@ -52,7 +70,6 @@ describe('create-nx-workspace', () => {

checkFilesExist('package.json');
checkFilesExist('project.json');
checkFilesExist('src/app/app.routes.ts');
checkFilesDoNotExist('src/app/app.module.ts');
expectCodeIsFormatted();
});
Expand Down Expand Up @@ -96,7 +113,7 @@ describe('create-nx-workspace', () => {
it('should be able to create an empty workspace built for apps', () => {
const wsName = uniq('apps');
runCreateWorkspace(wsName, {
preset: 'apps',
preset: 'empty',
packageManager,
});

Expand All @@ -106,6 +123,9 @@ describe('create-nx-workspace', () => {
'apps/.gitkeep',
'libs/.gitkeep'
);
const foreignLockFiles = Object.keys(packageManagerLockFile)
.filter((pm) => pm !== packageManager)
.map((pm) => packageManagerLockFile[pm]);

expectNoAngularDevkit();
});
Expand Down Expand Up @@ -159,7 +179,7 @@ describe('create-nx-workspace', () => {
appName,
packageManager,
standaloneApi: false,
routing: false,
routing: true,
})
).toThrow();
});
Expand Down Expand Up @@ -247,7 +267,6 @@ describe('create-nx-workspace', () => {
it('should be able to create react-native workspace', () => {
const wsName = uniq('react-native');
const appName = uniq('app');
// TODO @meeroslav: let's run those only on macos or only if the `packageManager` is `npm`
runCreateWorkspace(wsName, {
preset: 'react-native',
appName,
Expand All @@ -261,7 +280,6 @@ describe('create-nx-workspace', () => {
it('should be able to create an expo workspace', () => {
const wsName = uniq('expo');
const appName = uniq('app');
// TODO @meeroslav: let's run those only on macos or only if the `packageManager` is `npm`
runCreateWorkspace(wsName, {
preset: 'expo',
appName,
Expand All @@ -275,7 +293,7 @@ describe('create-nx-workspace', () => {
it('should be able to create a workspace with a custom base branch and HEAD', () => {
const wsName = uniq('branch');
runCreateWorkspace(wsName, {
preset: 'apps',
preset: 'empty',
base: 'main',
packageManager,
});
Expand All @@ -284,7 +302,7 @@ describe('create-nx-workspace', () => {
it('should be able to create a workspace with custom commit information', () => {
const wsName = uniq('branch');
runCreateWorkspace(wsName, {
preset: 'apps',
preset: 'empty',
extraArgs:
'--commit.name="John Doe" --commit.email="[email protected]" --commit.message="Custom commit message!"',
packageManager,
Expand All @@ -304,24 +322,51 @@ describe('create-nx-workspace', () => {

it('should respect package manager preference', () => {
const wsName = uniq('pm');
const appName = uniq('app');

process.env.YARN_REGISTRY = `http://localhost:4872`;
process.env.SELECTED_PM = 'npm';

runCreateWorkspace(wsName, {
preset: 'apps',
preset: 'react-monorepo',
style: 'css',
appName,
packageManager: 'npm',
bundler: 'webpack',
});

checkFilesDoNotExist('yarn.lock');
checkFilesExist('package-lock.json');
expectCodeIsFormatted();
process.env.SELECTED_PM = packageManager;
});

it('should store package manager preference for angular', () => {
const wsName = uniq('pm');
const appName = uniq('app');

process.env.YARN_REGISTRY = `http://localhost:4872`;
process.env.SELECTED_PM = 'npm';

runCreateWorkspace(wsName, {
preset: 'angular-monorepo',
appName,
style: 'css',
packageManager: 'npm',
routing: true,
standaloneApi: false,
});

checkFilesDoNotExist('yarn.lock');
checkFilesExist('package-lock.json');
expectCodeIsFormatted();
process.env.SELECTED_PM = packageManager;
});

it('should return error when ci workflow is selected but no cloud is set up', () => {
const wsName = uniq('github');
runCreateWorkspace(wsName, {
preset: 'apps',
const create = runCreateWorkspace(wsName, {
preset: 'npm',
packageManager,
ci: 'circleci',
});
Expand All @@ -333,7 +378,7 @@ describe('create-nx-workspace', () => {
function setupProject(envPm: 'npm' | 'yarn' | 'pnpm') {
process.env.SELECTED_PM = envPm;
runCreateWorkspace(uniq('pm'), {
preset: 'apps',
preset: 'empty',
packageManager: envPm,
useDetectedPm: true,
});
Expand Down Expand Up @@ -380,7 +425,7 @@ describe('create-nx-workspace', () => {

describe('create-nx-workspace custom parent folder', () => {
const tmpDir = `${e2eCwd}/${uniq('with space')}`;
const wsName = uniq('parent');
const wsName = uniq('empty');
const packageManager = getSelectedPackageManager() || 'pnpm';

afterEach(() => cleanupProject({ cwd: `${tmpDir}/${wsName}` }));
Expand Down

0 comments on commit 7fc2e8a

Please sign in to comment.