Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(testing): add lerna-smoke-tests #14347

Merged
merged 6 commits into from
Jan 17, 2023
Merged
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
29 changes: 9 additions & 20 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ jobs:
NX_E2E_RUN_CYPRESS: 'false'
NX_VERBOSE_LOGGING: 'false'
steps:
- run:
name: Configure git metadata (needed for lerna smoke tests)
command: |
git config --global user.email [email protected]
git config --global user.name "Test Test"
- run:
name: Set dynamic nx run variable
command: |
Expand Down Expand Up @@ -192,7 +197,7 @@ jobs:
pids+=($!)

(yarn nx affected --target=build --base=$NX_BASE --head=$NX_HEAD --parallel=3 &&
npx nx affected --target=e2e --base=$NX_BASE --head=$NX_HEAD --exclude=e2e-storybook,e2e-storybook-angular,e2e-react-native,e2e-detox --parallel=1) &
npx nx affected --target=e2e --base=$NX_BASE --head=$NX_HEAD --exclude=e2e-storybook,e2e-storybook-angular --parallel=1) &
pids+=($!)

for pid in "${pids[@]}"; do
Expand All @@ -213,27 +218,11 @@ jobs:
echo "export NX_RUN_GROUP=\"run-group-macos-$CIRCLE_WORKFLOW_ID\";" >> $BASH_ENV
- setup:
os: macos
- nx/set-shas:
main-branch-name: 'master'
- run:
name: Check if "detox" or "react-native" were modified directly
command: |
COUNT=`git diff --name-only $NX_BASE $NX_HEAD | (grep -E 'packages/detox|packages/react-native|e2e/detox|e2e/react-native' || true) | wc -l`
if [[ $COUNT -gt 0 ]]; then
echo "React Native and Detox were touched directly"
echo "export E2E_AFFECTED=true;" >> $BASH_ENV
else
echo "React Native and Detox were not touched directly"
echo "export E2E_AFFECTED=false;" >> $BASH_ENV
fi
- run:
name: Run E2E Tests
name: Run E2E Tests for macOS
# FIXME: remove --exclude=e2e-detox once we have a fix for the detox tests
command: |
if $E2E_AFFECTED; then
npx nx affected --target=e2e --base=$NX_BASE --head=$NX_HEAD --exclude=e2e-make-angular-cli-faster,e2e-detox,e2e-js,e2e-next,e2e-workspace-create,e2e-nx-run,e2e-nx-misc,e2e-react,e2e-web,e2e-webpack,e2e-rollup,e2e-esbuild,e2e-angular-extensions,e2e-angular-core,e2e-nx-plugin,e2e-cypress,e2e-node,e2e-linter,e2e-jest,e2e-add-nx-to-monorepo,nx-dev-e2e,e2e-nx-init,e2e-graph-client,e2e-vite,e2e-cra-to-nx,e2e-storybook,e2e-storybook-angular --parallel=1;
else
echo "Skipping E2E tests";
fi
npx nx run-many -t e2e-macos --parallel=1 --exclude=e2e-detox
no_output_timeout: 45m

# -------------------------
Expand Down
2 changes: 1 addition & 1 deletion e2e/detox/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"sourceRoot": "e2e/detox",
"projectType": "application",
"targets": {
"e2e": {},
"e2e-macos": {},
"run-e2e-tests": {}
},
"implicitDependencies": ["detox"]
Expand Down
11 changes: 11 additions & 0 deletions e2e/lerna-smoke-tests/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
export default {
transform: {
'^.+\\.[tj]sx?$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
maxWorkers: 1,
globals: { 'ts-jest': { tsconfig: '<rootDir>/tsconfig.spec.json' } },
displayName: 'e2e-lerna-smoke-tests',
preset: '../../jest.preset.js',
};
11 changes: 11 additions & 0 deletions e2e/lerna-smoke-tests/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "e2e-lerna-smoke-tests",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "e2e/lerna-smoke-tests",
"projectType": "application",
"targets": {
"e2e": {},
"run-e2e-tests": {}
},
"implicitDependencies": ["nx", "devkit"]
}
79 changes: 79 additions & 0 deletions e2e/lerna-smoke-tests/src/lerna-smoke-tests.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* These minimal smoke tests are here to ensure that we do not break assumptions on the lerna side
* when making updates to nx or @nrwl/devkit.
*/

import {
cleanupLernaWorkspace,
newLernaWorkspace,
runLernaCLI,
tmpProjPath,
updateJson,
} from '@nrwl/e2e/utils';

expect.addSnapshotSerializer({
serialize(str: string) {
return (
str
// Not all package managers print the package.json path in the output
.replace(tmpProjPath(), '')
.replace('/private', '')
.replace('/packages/package-1', '')
// We trim each line to reduce the chances of snapshot flakiness
.split('\n')
.map((r) => r.trim())
.join('\n')
);
},
test(val: string) {
return val != null && typeof val === 'string';
},
});

describe('Lerna Smoke Tests', () => {
beforeAll(() => newLernaWorkspace());
afterAll(() => cleanupLernaWorkspace());

// `lerna repair` builds on top of `nx repair` and runs all of its generators
describe('lerna repair', () => {
// If this snapshot fails it means that nx repair generators are making assumptions which don't hold true for lerna workspaces
it('should complete successfully on a new lerna workspace', async () => {
expect(runLernaCLI(`repair`)).toMatchInlineSnapshot(`

> Lerna No changes were necessary. This workspace is up to date!


`);
}, 1000000);
});

// `lerna run` delegates to the nx task runner behind the scenes
describe('lerna run', () => {
it('should complete successfully on a new lerna workspace', async () => {
runLernaCLI('create package-1 -y');
updateJson('packages/package-1/package.json', (json) => ({
...json,
scripts: {
...(json.scripts || {}),
'print-name': 'echo test-package-1',
},
}));

expect(runLernaCLI(`run print-name`)).toMatchInlineSnapshot(`

> package-1:print-name

> [email protected] print-name
> echo test-package-1
test-package-1



> Lerna (powered by Nx) Successfully ran target print-name for project package-1



`);
}, 1000000);
});
});
13 changes: 13 additions & 0 deletions e2e/lerna-smoke-tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"types": ["node", "jest"]
},
"include": [],
"files": [],
"references": [
{
"path": "./tsconfig.spec.json"
}
]
}
20 changes: 20 additions & 0 deletions e2e/lerna-smoke-tests/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"**/*.test.ts",
"**/*.spec.ts",
"**/*.spec.tsx",
"**/*.test.tsx",
"**/*.spec.js",
"**/*.test.js",
"**/*.spec.jsx",
"**/*.test.jsx",
"**/*.d.ts",
"jest.config.ts"
]
}
2 changes: 1 addition & 1 deletion e2e/react-native/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"sourceRoot": "e2e/react-native",
"projectType": "application",
"targets": {
"e2e": {},
"e2e-macos": {},
"run-e2e-tests": {}
},
"implicitDependencies": ["react-native"]
Expand Down
Loading