-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
lucas-zimerman
wants to merge
36
commits into
main
Choose a base branch
from
test/sibling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
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 691d2df
add e2e tests (WIP)
lucas-zimerman d5f3bbf
use E2E flag
lucas-zimerman 7b5c8db
remove tests
lucas-zimerman 8f47398
set e2e test name
lucas-zimerman 6e6fbea
setup yalc
lucas-zimerman a26b620
disable flaky test
lucas-zimerman fa16b47
add safe check on getting the package manager version
lucas-zimerman b5f3fb4
message and stack
lucas-zimerman c42b471
test
lucas-zimerman 4955a1d
test
lucas-zimerman a6d2e97
add path log
lucas-zimerman e94c293
test
lucas-zimerman cd04077
check if corepack will sort this
lucas-zimerman 429dbbd
add ref
lucas-zimerman d4c885d
test add corepack check
lucas-zimerman b1ac473
lets log artifacts if they fail
lucas-zimerman 9c5b450
correct log
lucas-zimerman 3d5dcb5
correct log
lucas-zimerman 95627cb
Merge branch 'main' of https://github.com/getsentry/sentry-capacitor …
lucas-zimerman 0d6a976
use newer upload artifact
lucas-zimerman 142f78b
use static version
lucas-zimerman bcd9b8c
add corepack check
lucas-zimerman a58f63d
install corepack
lucas-zimerman 960b88f
test
lucas-zimerman 2a44287
sync path
lucas-zimerman 6428a88
verbose error
lucas-zimerman d326411
more verbose error
lucas-zimerman cebc4b4
null safety
lucas-zimerman 49b8e40
sync env
lucas-zimerman df6ad32
remove corepack setup
lucas-zimerman 59f97b3
only pass PATH
lucas-zimerman d021658
compare env
lucas-zimerman 3d4f19e
remove test and use node
lucas-zimerman 47eeac8
test - hide global yarn
lucas-zimerman 3e258d6
fix path on install script
lucas-zimerman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": { | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
e2e-test/scripts/siblingsTests/yarn_v1/packagemanager.package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
rm yalc.lock | ||
rm package.json | ||
mv package.json.bak package.json | ||
|
||
cd ../../.. | ||
|
||
# Run Jest | ||
jest -c jest.e2e.config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
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); | ||
}); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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