Skip to content
New issue

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

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

Already on GitHub? # to your account

feat/WIP: e2e sibling test #795

Draft
wants to merge 36 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 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
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ node_modules/
# Jest generated folder
coverage/

# e2e siblings
/e2e-test/scripts/siblingsTests/*/*/package.json
/e2e-test/scripts/siblingsTests/*/*/yarn.lock
/e2e-test/scripts/siblingsTests/*/*/stdout.txt
/e2e-test/scripts/siblingsTests/.yalc

# example files
example/*/dist
example/*/node_modules
Expand Down
7 changes: 7 additions & 0 deletions e2e-test/scripts/siblingsTests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "2e2-sibling-test",
"version": "1.0.0",
"license": "MIT",
"dependencies": {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
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 @@ -73,9 +74,11 @@
"@sentry-internal/eslint-plugin-sdk": "8.37.1",
"@sentry-internal/typescript": "8.37.1",
"@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 @@ -126,7 +129,8 @@
"js"
],
"testPathIgnorePatterns": [
"<rootDir>/sample/"
"<rootDir>/sample/",
"<rootDir>/test/scripts/"
],
"testEnvironment": "node",
"testMatch": [
Expand Down
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


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

cd ../../..

# Run Jest
jest -c jest.e2e.config.js
153 changes: 153 additions & 0 deletions test/scripts/check-siblings.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import { spawnSync } from 'child_process';
import fs from 'fs-extra';
import path from 'path';

const e2ePath = path.resolve(__dirname, '../../', 'e2e-test/scripts/siblingsTests');
const SDKPath = path.resolve(e2ePath, '.yalc/@sentry/capacitor/');
const CapacitorInstallArg = `file:${SDKPath}`

/**
* Reads a JSON file or returns an empty object if the file doesn't exist.
* @param filePath The path to the JSON file.
* @returns Parsed JSON object or an empty object.
*/
const readJsonOrEmpty = (filePath: string): Record<string, any> => {
if (fs.existsSync(filePath)) {
const data = fs.readFileSync(filePath, 'utf8');
return JSON.parse(data);
} else {
return {};
}
};

function SentryCapacitorVersion(): string {
const packageJsonPath = path.join(SDKPath, 'package.json');
const packageJson = readJsonOrEmpty(packageJsonPath);
if (packageJson.version === undefined) {
throw new Error(`Sentry Capacitor version not found on path ${packageJsonPath}`);
}
return packageJson.version;
}

function ValidSentrySiblingVersion(): string {
const packageJsonPath = path.join(SDKPath, 'package.json');
const packageJson = readJsonOrEmpty(packageJsonPath);
const peerDependency = packageJson.peerDependencies?.['@sentry/angular'];
if (peerDependency === undefined) {
throw new Error(`Sentry Capacitor version not found on path ${packageJsonPath}`);
}
return peerDependency;
}

function ClearE2ETestFolder(testPath: string): void {
const yarnPath = path.join(testPath, 'yarn.lock');
const packagePath = path.join(testPath, 'package.lock');
fs.remove(yarnPath);
fs.remove(packagePath);
}

function GetInitialE2EPackage(testPath: string):{ [x: string]: any; }{
const rootPackage = path.join(testPath, 'start.package.json');
const packageManagerPath = path.join(testPath, '../', 'packagemanager.package.json');
const e2ePackagePath = path.join(testPath, '../../', 'package.json');

const file1 = readJsonOrEmpty(e2ePackagePath);
const file2 = readJsonOrEmpty(packageManagerPath);
const file3 = readJsonOrEmpty(rootPackage);

return {
...file1,
...file2,
...file3
};

}

function CreateE2EPackage(testPath: string): void {
const newPackagePath = path.join(testPath, 'package.json');
const mergedPackageJson = GetInitialE2EPackage(testPath);
fs.writeFileSync(newPackagePath, JSON.stringify(mergedPackageJson, null, 2), 'utf8');
}


/*
async function SetupPackageManager(rootPath: string): void
{
// const outputStream = fs.openSync(path.join(rootPath, 'install.log'), 'w');
// const errorStream = fs.openSync(path.join(rootPath, 'error.log'), 'w');

const result = spawnSync('corepack', ['prepare', pakcageManagerVersion, '--activate', '--yes'], {
cwd: rootPath,
stdio: 'inherit'// inherit', outputStream, errorStream], // Ensure output is in readable string format
});
// fs.closeSync(outputStream);
// fs.closeSync(errorStream);
await wait(3); // Wait for 3 seconds
expect(result.error).toBeEmpty();
}
*/

function InstallSDK(args: ReadonlyArray<string>, rootPath: string): ReturnType<typeof spawnSync>
{
const outputStream = fs.openSync(path.join(rootPath, 'install.log'), 'w');
const errorStream = fs.openSync(path.join(rootPath, 'error.log'), 'w');

const result = spawnSync('yarn', args, {
cwd: rootPath,
stdio: ['inherit', outputStream, errorStream], // Ensure output is in readable string format
});
fs.closeSync(outputStream);
fs.closeSync(errorStream);
return result;
}

function InvokePostInstall(rootPath: string): ReturnType<typeof spawnSync>
{
const outputStream = fs.openSync(path.join(rootPath, 'install.log'), 'a');
const errorStream = fs.openSync(path.join(rootPath, 'error.log'), 'a');

const result = spawnSync('yarn', ['install', '--force'], {
cwd: rootPath,
stdio: ['inherit', outputStream, errorStream], // Ensure output is in readable string format
});
fs.closeSync(outputStream);
fs.closeSync(errorStream);
return result;
}

describe('Yarn V1', () => {
const yarnV1e2ePath = path.join(e2ePath, 'yarn_v1');

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

Check failure on line 124 in test/scripts/check-siblings.test.ts

View workflow job for this annotation

GitHub Actions / Build

'capacitorVersion' is assigned a value but never used
const siblingVersion = ValidSentrySiblingVersion();

const testPath = path.join(yarnV1e2ePath, 'correct_sibling');
const packageJsonPath = path.join(testPath, 'package.json');

const expectedPackageJson = {
...GetInitialE2EPackage(testPath),
dependencies: {
'@sentry/capacitor': CapacitorInstallArg,
'@sentry/angular': siblingVersion
}
};
ClearE2ETestFolder(testPath);
CreateE2EPackage(testPath);
// await SetupPackageManager(testPath);

// Test
const result = InstallSDK(['add', CapacitorInstallArg ,`@sentry/angular@${siblingVersion}`, '--force'], testPath);
const packageJson = readJsonOrEmpty(packageJsonPath);
const postInstallResult = InvokePostInstall(testPath);

// Expect
expect(result.status).toBe(0);
expect(postInstallResult.status).toBe(0);
expect(packageJson).toEqual(expectedPackageJson);
});

});
});
24 changes: 24 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,14 @@
dependencies:
"@babel/types" "^7.20.7"

"@types/fs-extra@^11.0.4":
version "11.0.4"
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-11.0.4.tgz#e16a863bb8843fba8c5004362b5a73e17becca45"
integrity sha512-yTbItCNreRooED33qjunPthRcSjERP1r4MqCZc7wv0u2sUkzTFp45tgUfS5+r7FrZPdmCCNflLhVSP/o+SemsQ==
dependencies:
"@types/jsonfile" "*"
"@types/node" "*"

"@types/fs-extra@^8.0.0":
version "8.1.4"
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-8.1.4.tgz#8171df1d16a80d69fc9c3aab07d7961349a5cb8b"
Expand Down Expand Up @@ -1275,6 +1283,13 @@
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
integrity sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==

"@types/jsonfile@*":
version "6.1.4"
resolved "https://registry.yarnpkg.com/@types/jsonfile/-/jsonfile-6.1.4.tgz#614afec1a1164e7d670b4a7ad64df3e7beb7b702"
integrity sha512-D5qGUYwjvnNNextdU59/+fI+spnwtTFmyQP0h+PfIOSkNfpU6AOICUOkm4i0OnSk+NyjdPJrxCDro0sJsWlRpQ==
dependencies:
"@types/node" "*"

"@types/node@*":
version "20.8.9"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.8.9.tgz#646390b4fab269abce59c308fc286dcd818a2b08"
Expand Down Expand Up @@ -2647,6 +2662,15 @@ form-data@^4.0.0:
combined-stream "^1.0.8"
mime-types "^2.1.12"

fs-extra@^11.2.0:
version "11.2.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-11.2.0.tgz#e70e17dfad64232287d01929399e0ea7c86b0e5b"
integrity sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==
dependencies:
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^2.0.0"

fs-extra@^9.0.0:
version "9.1.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.1.0.tgz#5954460c764a8da2094ba3554bf839e6b9a7c86d"
Expand Down
Loading