Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 6 additions & 10 deletions .nx/workflows/dynamic-changesets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,17 @@ assignment-rules:
parallelism: 1

- projects:
- e2e-angular
- e2e-react
- e2e-next
- e2e-web
- e2e-eslint
- e2e-remix
- e2e-cypress
- e2e-docker
- e2e-js
targets:
- e2e-ci**react-package**
- e2e-ci**react.test**
- e2e-ci**react-router-ts-solution**
- e2e-ci**next-e2e-and-snapshots**
- e2e-ci**next-generation**
- e2e-ci**next-ts-solutions**
- e2e-ci**next-webpack**
- e2e-ci**web**
- e2e-ci**remix-ts-solution**
- e2e-ci**linter**
- e2e-ci**
run-on:
- agent: linux-large
parallelism: 1
Expand Down
50 changes: 50 additions & 0 deletions e2e/nx/src/misc-cross-workspace.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {
cleanupProject,
newProject,
runCLI,
uniq,
updateFile,
} from '@nx/e2e-utils';
import { join } from 'path';

describe('cross-workspace implicit dependencies', () => {
beforeAll(() =>
newProject({
packages: ['@nx/js'],
})
);

afterAll(() => cleanupProject());

it('should successfully build a project graph when cross-workspace implicit dependencies are present', () => {
const npmPackage = uniq('npm-package');
runCLI(`generate @nx/workspace:npm-package ${npmPackage}`);

function setImplicitDependencies(deps: string[]) {
updateFile(join(npmPackage, 'package.json'), (content) => {
const json = JSON.parse(content);
json.nx = {
...json.nx,
implicitDependencies: deps,
};
return JSON.stringify(json, null, 2);
});
}

// First set the implicit dependencies to an intentionally invalid value to prove the command fails during project graph construction
setImplicitDependencies(['this-project-does-not-exist']);
expect(
runCLI(`test ${npmPackage}`, {
silenceError: true,
})
).toContain('Failed to process project graph');

// Now set the implicit dependencies to a cross-workspace reference to prove that it is valid, despite not being resolvable in the current workspace
setImplicitDependencies(['nx-cloud:another-workspace']);
expect(
runCLI(`test ${npmPackage}`, {
silenceError: true,
})
).toContain('Successfully ran target test');
});
});
173 changes: 173 additions & 0 deletions e2e/nx/src/misc-format.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
import {
cleanupProject,
isNotWindows,
runCLI,
runCLIAsync,
uniq,
updateFile,
} from '@nx/e2e-utils';
import * as path from 'path';
import { setupMiscTests } from './misc-setup';

describe('Nx Commands - format', () => {
const myapp = uniq('myapp');
const mylib = uniq('mylib');

beforeAll(() => {
setupMiscTests();
runCLI(`generate @nx/web:app apps/${myapp}`);
runCLI(`generate @nx/js:lib libs/${mylib}`);
});

afterAll(() => cleanupProject());

beforeEach(() => {
updateFile(
`apps/${myapp}/src/main.ts`,
`
const x = 1111;
`
);

updateFile(
`apps/${myapp}/src/app/app.element.spec.ts`,
`
const y = 1111;
`
);

updateFile(
`apps/${myapp}/src/app/app.element.ts`,
`
const z = 1111;
`
);

updateFile(
`libs/${mylib}/index.ts`,
`
const x = 1111;
`
);
updateFile(
`libs/${mylib}/src/${mylib}.spec.ts`,
`
const y = 1111;
`
);

updateFile(
`README.md`,
`
my new readme;
`
);
});

it('should check libs and apps specific files', async () => {
if (isNotWindows()) {
const stdout = runCLI(
`format:check --files="libs/${mylib}/index.ts,package.json" --libs-and-apps`,
{ silenceError: true }
);
expect(stdout).toContain(path.normalize(`libs/${mylib}/index.ts`));
expect(stdout).toContain(
path.normalize(`libs/${mylib}/src/${mylib}.spec.ts`)
);
expect(stdout).not.toContain(path.normalize(`README.md`)); // It will be contained only in case of exception, that we fallback to all
}
}, 90000);

it('should check specific project', async () => {
if (isNotWindows()) {
const stdout = runCLI(`format:check --projects=${myapp}`, {
silenceError: true,
});
expect(stdout).toContain(path.normalize(`apps/${myapp}/src/main.ts`));
expect(stdout).toContain(
path.normalize(`apps/${myapp}/src/app/app.element.ts`)
);
expect(stdout).toContain(
path.normalize(`apps/${myapp}/src/app/app.element.spec.ts`)
);
expect(stdout).not.toContain(path.normalize(`libs/${mylib}/index.ts`));
expect(stdout).not.toContain(
path.normalize(`libs/${mylib}/src/${mylib}.spec.ts`)
);
expect(stdout).not.toContain(path.normalize(`README.md`));
}
}, 90000);

it('should check multiple projects', async () => {
if (isNotWindows()) {
const stdout = runCLI(`format:check --projects=${myapp},${mylib}`, {
silenceError: true,
});
expect(stdout).toContain(path.normalize(`apps/${myapp}/src/main.ts`));
expect(stdout).toContain(
path.normalize(`apps/${myapp}/src/app/app.element.spec.ts`)
);
expect(stdout).toContain(
path.normalize(`apps/${myapp}/src/app/app.element.ts`)
);
expect(stdout).toContain(path.normalize(`libs/${mylib}/index.ts`));
expect(stdout).toContain(
path.normalize(`libs/${mylib}/src/${mylib}.spec.ts`)
);
expect(stdout).not.toContain(path.normalize(`README.md`));
}
}, 90000);

it('should check all', async () => {
if (isNotWindows()) {
const stdout = runCLI(`format:check --all`, { silenceError: true });
expect(stdout).toContain(path.normalize(`apps/${myapp}/src/main.ts`));
expect(stdout).toContain(
path.normalize(`apps/${myapp}/src/app/app.element.spec.ts`)
);
expect(stdout).toContain(
path.normalize(`apps/${myapp}/src/app/app.element.ts`)
);
expect(stdout).toContain(path.normalize(`libs/${mylib}/index.ts`));
expect(stdout).toContain(
path.normalize(`libs/${mylib}/src/${mylib}.spec.ts`)
);
expect(stdout).toContain(path.normalize(`README.md`));
}
}, 90000);

it('should throw error if passing both projects and --all param', async () => {
if (isNotWindows()) {
const { stderr } = await runCLIAsync(
`format:check --projects=${myapp},${mylib} --all`,
{
silenceError: true,
}
);
expect(stderr).toContain(
'Arguments all and projects are mutually exclusive'
);
}
}, 90000);

it('should reformat the code', async () => {
if (isNotWindows()) {
runCLI(
`format:write --files="apps/${myapp}/src/app/app.element.spec.ts,apps/${myapp}/src/app/app.element.ts"`
);
const stdout = runCLI('format:check --all', { silenceError: true });
expect(stdout).toContain(path.normalize(`apps/${myapp}/src/main.ts`));
expect(stdout).not.toContain(
path.normalize(`apps/${myapp}/src/app/app.element.spec.ts`)
);
expect(stdout).not.toContain(
path.normalize(`apps/${myapp}/src/app/app.element.ts`)
);

runCLI('format:write --all');
expect(runCLI('format:check --all')).not.toContain(
path.normalize(`apps/${myapp}/src/main.ts`)
);
}
}, 300000);
});
144 changes: 144 additions & 0 deletions e2e/nx/src/misc-global-installation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import {
createNonNxProjectDirectory,
e2eCwd,
getPackageManagerCommand,
getPublishedVersion,
newProject,
readFile,
readJson,
runCommand,
updateFile,
updateJson,
} from '@nx/e2e-utils';
import { ensureDirSync, writeFileSync } from 'fs-extra';
import * as path from 'path';
import { major } from 'semver';

describe('global installation', () => {
// Additionally, installing Nx under e2eCwd like this still acts like a global install,
// but is easier to cleanup and doesn't mess with the users PC if running tests locally.
const globalsPath = path.join(e2eCwd, 'globals', 'node_modules', '.bin');

let oldPath: string;

beforeAll(() => {
ensureDirSync(globalsPath);
writeFileSync(
path.join(path.dirname(path.dirname(globalsPath)), 'package.json'),
JSON.stringify(
{
dependencies: {
nx: getPublishedVersion(),
},
},
null,
2
)
);

runCommand(getPackageManagerCommand().install, {
cwd: path.join(e2eCwd, 'globals'),
});

// Update process.path to have access to modules installed in e2ecwd/node_modules/.bin,
// this lets commands run things like `nx`. We put it at the beginning so they are found first.
oldPath = process.env.PATH;
process.env.PATH = globalsPath + path.delimiter + process.env.PATH;
});

afterAll(() => {
process.env.PATH = oldPath;
});

describe('inside nx directory', () => {
beforeAll(() => {
newProject();
});

it('should invoke Nx commands from local repo', () => {
const nxJsContents = readFile('node_modules/nx/bin/nx.js');
updateFile('node_modules/nx/bin/nx.js', `console.log('local install');`);
let output: string;
expect(() => {
output = runCommand(`nx show projects`);
}).not.toThrow();
expect(output).toContain('local install');
updateFile('node_modules/nx/bin/nx.js', nxJsContents);
});

it('should warn if local Nx has higher major version', () => {
const packageJsonContents = readFile('node_modules/nx/package.json');
updateJson('node_modules/nx/package.json', (json) => {
json.version = `${major(getPublishedVersion()) + 2}.0.0`;
return json;
});
let output: string;
expect(() => {
output = runCommand(`nx show projects`);
}).not.toThrow();
expect(output).toContain(`It's time to update Nx`);
updateFile('node_modules/nx/package.json', packageJsonContents);
});

it('--version should display global installs version', () => {
const packageJsonContents = readFile('node_modules/nx/package.json');
const localVersion = `${major(getPublishedVersion()) + 2}.0.0`;
updateJson('node_modules/nx/package.json', (json) => {
json.version = localVersion;
return json;
});
let output: string;
expect(() => {
output = runCommand(`nx --version`);
}).not.toThrow();
expect(output).toContain(`- Local: v${localVersion}`);
expect(output).toContain(`- Global: v${getPublishedVersion()}`);
updateFile('node_modules/nx/package.json', packageJsonContents);
});

it('report should display global installs version', () => {
const packageJsonContents = readFile('node_modules/nx/package.json');
const localVersion = `${major(getPublishedVersion()) + 2}.0.0`;
updateJson('node_modules/nx/package.json', (json) => {
json.version = localVersion;
return json;
});
let output: string;
expect(() => {
output = runCommand(`nx report`);
}).not.toThrow();
expect(output).toEqual(
expect.stringMatching(new RegExp(`nx.*:.*${localVersion}`))
);
expect(output).toEqual(
expect.stringMatching(
new RegExp(`nx \\(global\\).*:.*${getPublishedVersion()}`)
)
);
updateFile('node_modules/nx/package.json', packageJsonContents);
});
});

describe('non-nx directory', () => {
beforeAll(() => {
createNonNxProjectDirectory();
});

it('--version should report global version and local not found', () => {
let output: string;
expect(() => {
output = runCommand(`nx --version`);
}).not.toThrow();
expect(output).toContain(`- Local: Not found`);
expect(output).toContain(`- Global: v${getPublishedVersion()}`);
});

it('graph should work in npm workspaces repo', () => {
expect(() => {
runCommand(`nx graph --file graph.json`);
}).not.toThrow();
const { graph } = readJson('graph.json');
expect(graph).toHaveProperty('nodes');
});
});
});
Loading
Loading