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

feat/WIP: e2e sibling test #795

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
32965f2
idea of e2e sibling test
lucas-zimerman Nov 26, 2024
691d2df
add e2e tests (WIP)
lucas-zimerman Dec 3, 2024
d5f3bbf
use E2E flag
lucas-zimerman Dec 3, 2024
7b5c8db
remove tests
lucas-zimerman Dec 3, 2024
8f47398
set e2e test name
lucas-zimerman Dec 3, 2024
6e6fbea
setup yalc
lucas-zimerman Dec 3, 2024
a26b620
disable flaky test
lucas-zimerman Dec 10, 2024
fa16b47
add safe check on getting the package manager version
lucas-zimerman Dec 10, 2024
b5f3fb4
message and stack
lucas-zimerman Dec 10, 2024
c42b471
test
lucas-zimerman Dec 10, 2024
4955a1d
test
lucas-zimerman Dec 10, 2024
a6d2e97
add path log
lucas-zimerman Dec 10, 2024
e94c293
test
lucas-zimerman Dec 10, 2024
cd04077
check if corepack will sort this
lucas-zimerman Dec 10, 2024
429dbbd
add ref
lucas-zimerman Dec 10, 2024
d4c885d
test add corepack check
lucas-zimerman Dec 10, 2024
b1ac473
lets log artifacts if they fail
lucas-zimerman Dec 10, 2024
9c5b450
correct log
lucas-zimerman Dec 10, 2024
3d5dcb5
correct log
lucas-zimerman Dec 10, 2024
95627cb
Merge branch 'main' of https://github.com/getsentry/sentry-capacitor …
lucas-zimerman Jan 6, 2025
0d6a976
use newer upload artifact
lucas-zimerman Jan 6, 2025
142f78b
use static version
lucas-zimerman Jan 6, 2025
bcd9b8c
add corepack check
lucas-zimerman Jan 6, 2025
a58f63d
install corepack
lucas-zimerman Jan 6, 2025
960b88f
test
lucas-zimerman Jan 6, 2025
2a44287
sync path
lucas-zimerman Jan 6, 2025
6428a88
verbose error
lucas-zimerman Jan 6, 2025
d326411
more verbose error
lucas-zimerman Jan 6, 2025
cebc4b4
null safety
lucas-zimerman Jan 6, 2025
49b8e40
sync env
lucas-zimerman Jan 6, 2025
df6ad32
remove corepack setup
lucas-zimerman Jan 6, 2025
59f97b3
only pass PATH
lucas-zimerman Jan 6, 2025
d021658
compare env
lucas-zimerman Jan 6, 2025
3d4f19e
remove test and use node
lucas-zimerman Jan 6, 2025
47eeac8
test - hide global yarn
lucas-zimerman Jan 6, 2025
3e258d6
fix path on install script
lucas-zimerman Jan 6, 2025
b40bded
Merge branch 'main' of https://github.com/getsentry/sentry-capacitor …
lucas-zimerman Feb 3, 2025
11af74f
reduce complexity and use default npm
lucas-zimerman Feb 3, 2025
a168a00
test cache
lucas-zimerman Feb 3, 2025
de0a0d8
remove todo
lucas-zimerman Feb 3, 2025
b037484
use different e2e log check
lucas-zimerman Feb 3, 2025
de70877
nit
lucas-zimerman Feb 3, 2025
bdcf2fc
Merge branch 'main' into test/sibling
lucas-zimerman Feb 11, 2025
ab94537
remove unused code, clear logs
lucas-zimerman Feb 11, 2025
9ebf608
nit
lucas-zimerman Feb 11, 2025
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
54 changes: 54 additions & 0 deletions .github/workflows/buildandtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,60 @@ jobs:
- name: Run tests
run: yarn test

job_e2e_test:
name: E2E Test
needs: job_build
continue-on-error: true
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- name: Check out current commit (${{ github.sha }})
uses: actions/checkout@v4

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install Corepack
run: npm install -g corepack

- run: corepack enable

- name: Install Yarn v3
run: corepack prepare yarn@3.8.6 --activate

- name: Install Yarn v1
run: corepack prepare yarn@1.22.22 --activate

- name: Check dependency cache
uses: actions/cache@v4.1.2
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ needs.job_build.outputs.dependency_cache_key }}
- name: Check build cache
uses: actions/cache@v4.1.2
with:
path: ${{ env.CACHED_BUILD_PATHS }}
key: ${{ env.BUILD_CACHE_KEY }}
- name: Install yalc
run: yarn global add yalc
- name: Run tests
run: |
yarn install
yarn test:e2e

- name: Upload failed artifact with test logs and JSON files
if: failure()
uses: actions/upload-artifact@v4.1.0
with:
name: failed-e2e-${{ github.run_id }}
path: |
./e2e-test/scripts/siblingsTests/npm*/*/*.log
./e2e-test/scripts/siblingsTests/npm*/*/*.json
./e2e-test/scripts/siblingsTests/yarn_*/*/*.log
./e2e-test/scripts/siblingsTests/yarn_*/*/*.json

job_artifacts:
name: Upload Artifacts
needs: job_build
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ node_modules/
# Jest generated folder
coverage/

# e2e siblings
/e2e-test/scripts/siblingsTests/*/newInstall*
/e2e-test/scripts/siblingsTests/*/update*
/e2e-test/scripts/siblingsTests/.yalc

# example files
example/*/dist
example/*/node_modules
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
11 changes: 11 additions & 0 deletions e2e-test/scripts/siblingsTests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "2e2-sibling-test",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"_comment": "postinstall scripts are not called from file packages so we copy the same post install from sentry capacitor",
"postinstall": "node node_modules/@sentry/capacitor/scripts/check-siblings.js"
},
"dependencies": {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"packageManager": "yarn@3.8.6"
}
16 changes: 16 additions & 0 deletions jest.e2e.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
testEnvironment: "node",
transform: {
"^.+\\.(ts)$": "ts-jest"
},
setupFilesAfterEnv: ["jest-extended/all"],
globals: {
"__DEV__": true,
"ts-jest": {
tsconfig: "./tsconfig.json",
diagnostics: false
}
},
moduleFileExtensions: ["ts", "js"],
testMatch: ["**/test/scripts/**/*.test.(ts|tsx)"],
};
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"watch": "tsc --watch",
"clean": "rimraf ./dist ./coverage",
"test": "jest",
"test:e2e": "./scripts/e2e-test.siblings.sh",
"test:watch": "jest --watch",
"lint": "eslint .",
"fix": "eslint --fix test/* src/*",
Expand Down Expand Up @@ -74,9 +75,11 @@
"@sentry-internal/eslint-plugin-sdk": "8.42.0",
"@sentry-internal/typescript": "8.42.0",
"@sentry/wizard": "3.34.2",
"@types/fs-extra": "^11.0.4",
"@types/jest": "^29.5.3",
"concurrently": "^8.2.2",
"eslint": "^7.13.0",
"fs-extra": "^11.2.0",
"jest": "^29.6.2",
"jest-extended": "^4.0.2",
"prettier": "^3.3.2",
Expand Down Expand Up @@ -127,7 +130,8 @@
"js"
],
"testPathIgnorePatterns": [
"<rootDir>/sample/"
"<rootDir>/sample/",
"<rootDir>/test/scripts/"
],
"testEnvironment": "node",
"testMatch": [
Expand Down
14 changes: 14 additions & 0 deletions scripts/check-siblings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ const updateArgument = '--update-sentry-capacitor';
// Filters all Sentry packages but Capacitor, CLI and Wizard.
const jsonFilter = /\s*\"\@sentry\/(?!capacitor|wizard|cli|typescript|electron)(?<packageName>[a-zA-Z]+)\"\:\s*\"(?<version>.+)\"/;

const IsE2E = env.sentry_e2e == 'true';

function LogE2E(message) {
IsE2E && console.log("E2E_TEST: " + message);
}

/**
* If user requested to ignore the post-install
* @return {Boolean} true if requested to skip the post-install check, false otherwise.
Expand Down Expand Up @@ -70,6 +76,7 @@ function ValidateSentryPackageParameters(packages, siblingVersion) {
}

if (errorMessages.length > 0) {
LogE2E("Incompatibility found");
console.error(`⚠️ ${errorMessages.join("\n")}`);
exit(1);
}
Expand Down Expand Up @@ -114,21 +121,26 @@ function FormatPackageInstallCommand(sentryPackages) {
}

function CheckSiblings() {
LogE2E("Invoked");
if (SkipPostInstall()) {
LogE2E("Skipped");
return;
}

const siblingVersion = GetRequiredSiblingVersion();
if (siblingVersion === undefined) {
LogE2E("Sibling not set");
return;
}
LogE2E(`Expecting sibling version ${siblingVersion}`);

// Method 1: Validate user parameters when requesting to install/update a new Package.
if (env.npm_config_argv) {
// Only available on Yarn.
const npmAction = JSON.parse(env.npm_config_argv);
if (npmAction.original && npmAction.original.length > 1) {
ValidateSentryPackageParameters(npmAction.original, siblingVersion);
LogE2E("OK");
return;
}
}
Expand All @@ -154,11 +166,13 @@ function CheckSiblings() {
`Please install the mentioned packages exactly with version ${siblingVersion} and with the argument ${updateArgument}.
Your project will build with the wrong package but you may face Runtime errors.
You can use the below command to fix your package.json:`);
LogE2E("Incompatibility found");

console.error(`⚠️ ${IncompatibilityError.join("\n")}`);
console.warn(` ${FormatPackageInstallCommand(packagesList)}`);
exit(1);
}
LogE2E("OK");
}

CheckSiblings();
23 changes: 23 additions & 0 deletions scripts/e2e-test.siblings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Publish with yalc
yalc publish --sig

# Navigate to siblingsTests and publish without modifying package.json
cd e2e-test/scripts/siblingsTests/

rm -r .yalc
rm -r node_modules

cp package.json package.json.bak

yalc add @sentry/capacitor
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We create this folder because it loads faster than pointing yarn to install the root project (10 minutes vs 5 seconds) on the sibling tests

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By this folder, do you mean e2e-test/scripts/siblingsTests?


rm yalc.lock
rm package.json
mv package.json.bak package.json

cd ../../..

# Run Jest
jest -c jest.e2e.config.js
118 changes: 118 additions & 0 deletions test/scripts/check-siblings.npm.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import path from 'path';
const { execSync } = require("child_process");

import { ClearE2ETestFolder, CreateE2EPackage, CreateE2EStartPackage, e2ePath, GetInitialE2EPackage, GetLogs, GetPackageManagerVersion, InstallSDK, InvalidSentrySiblingVersion, readJsonOrEmpty, SDKPath, ValidSentrySiblingVersion } from './check-siblingsHelper';

const CapacitorInstallArg = `file:${SDKPath}`

describe('NPM tests', () => {
const npme2ePath = path.join(e2ePath, 'npm_default');
const PackageMangerVersion = execSync("npm --version").toString().trim();

describe('new Install', () => {
test('no warnings when correct sibling is installed', async () => {
// Setup.
const siblingVersion = ValidSentrySiblingVersion();

const testPath = path.join(npme2ePath, 'newInstallCorrectSibling');
const packageJsonPath = path.join(testPath, 'package.json');

ClearE2ETestFolder(testPath);
CreateE2EPackage(testPath);

expect(GetPackageManagerVersion('npm', testPath)).toBe(PackageMangerVersion);

const expectedPackageJson = {
...GetInitialE2EPackage(testPath),
dependencies: {
'@sentry/capacitor': 'file:../../.yalc/@sentry/capacitor',
'@sentry/angular': siblingVersion
}
};


// Test
const result = InstallSDK('npm',['install', '--save-exact', '--foreground-scripts', CapacitorInstallArg, `@sentry/angular@${siblingVersion}`], testPath);
const packageJson = readJsonOrEmpty(packageJsonPath);
const e2eLogs = GetLogs(testPath);

// Expect
expect(result.status).toBe(0);
expect(packageJson).toEqual(expectedPackageJson);
expect(e2eLogs).toContain('E2E_TEST: OK');
});
});

describe('update packages', () => {
test('no warnings when correct sibling are updated', async () => {
// Setup.
const siblingVersion = ValidSentrySiblingVersion();

const testPath = path.join(npme2ePath, 'updateCorrectSibling');
const packageJsonPath = path.join(testPath, 'package.json');
const dependenciesJson = {
dependencies: {
'@sentry/capacitor': CapacitorInstallArg,
'@sentry/angular': siblingVersion
}
};

ClearE2ETestFolder(testPath);
CreateE2EStartPackage(testPath, dependenciesJson);
CreateE2EPackage(testPath);
expect(GetPackageManagerVersion('npm', testPath)).toBe(PackageMangerVersion);

const expectedPackageJson = {
...GetInitialE2EPackage(testPath),
...dependenciesJson
};

// Test
const result = InstallSDK('npm',['install'], testPath);
const packageJson = readJsonOrEmpty(packageJsonPath);
const e2eLogs = GetLogs(testPath);

// Expect
expect(result.status).toBe(0);
expect(packageJson).toEqual(expectedPackageJson);
expect(e2eLogs).toContain('E2E_TEST: OK');
});

test('warns when incorrect sibling is installed', async () => {
// Setup.
const siblingVersion = InvalidSentrySiblingVersion();

const testPath = path.join(npme2ePath, 'updateInorrectSibling');
const packageJsonPath = path.join(testPath, 'package.json');
const dependenciesJson = {
dependencies: {
'@sentry/capacitor': CapacitorInstallArg,
'@sentry/angular': siblingVersion
}
};

ClearE2ETestFolder(testPath);
CreateE2EStartPackage(testPath, dependenciesJson);
CreateE2EPackage(testPath);
expect(GetPackageManagerVersion('npm', testPath)).toBe(PackageMangerVersion);

const expectedPackageJson = {
...GetInitialE2EPackage(testPath),
...dependenciesJson
};

// Test
const result = InstallSDK('npm', ['install'], testPath);
const packageJson = readJsonOrEmpty(packageJsonPath);
const logs = GetLogs(testPath).join('\n');

// Expect
expect(result.status).toBe(1);
expect(packageJson).toEqual(expectedPackageJson);
expect(logs).toContain('E2E_TEST: Incompatibility found');
expect(logs).toContain(`⚠️ This version of Sentry Capacitor is incompatible with the following installed packages:
@sentry/angular version ${siblingVersion}`);
expect(logs).toContain(`npm install --save-exact @sentry/angular@${ValidSentrySiblingVersion()} --update-sentry-capacitor`);
});
});
});
Loading
Loading