Skip to content

Commit

Permalink
test(ember): Update ember tests to use E2E structure (#11827)
Browse files Browse the repository at this point in the history
This gets rid of the Ember canary tests that are always failing,
probably due to ember-try (which we use there) not playing nicely with
the monorepo etc.

Instead, this now uses the proper E2E setup. I added two tests, for
classic ember and modern embroider-based ember. While doing this I also
noticed two bugs I fixed along the way :O

This also removed the ember canary tests, IMHO the e2e tests are good
enough for us there now.
  • Loading branch information
mydea authored Jul 4, 2024
1 parent ef7e5b6 commit dc2659c
Show file tree
Hide file tree
Showing 97 changed files with 2,623 additions and 43 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,8 @@ jobs:
'node-express-esm-without-loader',
'node-express-cjs-preload',
'node-otel-sdk-node',
'ember-classic',
'ember-embroider',
'nextjs-app-dir',
'nextjs-14',
'nextjs-15',
Expand Down
42 changes: 0 additions & 42 deletions .github/workflows/canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,45 +151,3 @@ jobs:
with:
filename: .github/CANARY_FAILURE_TEMPLATE.md
update_existing: true

job_ember_canary_test:
name: Ember Canary Tests
runs-on: ubuntu-20.04
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
# scenario: [ember-release, embroider-optimized, ember-4.0]
scenario: [ember-4.0]
steps:
- name: 'Check out current commit'
uses: actions/checkout@v4
with:
ref: ${{ env.HEAD_COMMIT }}
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version-file: 'package.json'
- name: Install dependencies
run: yarn install --ignore-engines --frozen-lockfile

- name: Build dependencies
run: |
yarn lerna run build:types --scope=@sentry/ember --include-dependencies
yarn lerna run build:transpile --scope=@sentry/ember --include-dependencies
- name: Run Ember tests
run: |
cd packages/ember
yarn ember try:one ${{ matrix.scenario }} --skip-cleanup=true
- name: Create Issue
if: failure() && github.event_name == 'schedule'
uses: JasonEtco/create-an-issue@1b14a70e4d8dc185e5cc76d3bec9eab20257b2c5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RUN_LINK: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
TITLE: Ember Canary ${{ matrix.scenario }} Test Failed
with:
filename: .github/CANARY_FAILURE_TEMPLATE.md
update_existing: true
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"devDependencies": {
"@sentry-internal/test-utils": "link:../../../test-utils",
"@playwright/test": "^1.41.1",
"@playwright/test": "^1.44.1",
"wait-port": "1.0.4"
},
"volta": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 2

[*.hbs]
insert_final_newline = false

[*.{diff,md}]
trim_trailing_whitespace = false
15 changes: 15 additions & 0 deletions dev-packages/e2e-tests/test-applications/ember-classic/.ember-cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
/**
Ember CLI sends analytics information by default. The data is completely
anonymous, but there are times when you might want to disable this behavior.

Setting `disableAnalytics` to true will prevent any data from being sent.
*/
"disableAnalytics": false,

/**
Setting `isTypeScriptProject` to true will force the blueprint generators to generate TypeScript
rather than JavaScript by default, when a TypeScript version of a given blueprint is available.
*/
"isTypeScriptProject": false
}
32 changes: 32 additions & 0 deletions dev-packages/e2e-tests/test-applications/ember-classic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist/
/tmp/

# dependencies
/bower_components/
/node_modules/

# misc
/.env*
/.pnp*
/.sass-cache
/.eslintcache
/connect.lock
/coverage/
/libpeerconnection.log
/npm-debug.log*
/testem.log
/yarn-error.log

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/npm-shrinkwrap.json.ember-try
/package.json.ember-try
/package-lock.json.ember-try
/yarn.lock.ember-try

# broccoli-debug
/DEBUG/
2 changes: 2 additions & 0 deletions dev-packages/e2e-tests/test-applications/ember-classic/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@sentry:registry=http://127.0.0.1:4873
@sentry-internal:registry=http://127.0.0.1:4873
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignore_dirs": ["tmp", "dist"]
}
56 changes: 56 additions & 0 deletions dev-packages/e2e-tests/test-applications/ember-classic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# ember-classic

This README outlines the details of collaborating on this Ember application. A short introduction of this app could
easily go here.

## Prerequisites

You will need the following things properly installed on your computer.

- [Git](https://git-scm.com/)
- [Node.js](https://nodejs.org/) (with npm)
- [Ember CLI](https://cli.emberjs.com/release/)
- [Google Chrome](https://google.com/chrome/)

## Installation

- `git clone <repository-url>` this repository
- `cd ember-classic`
- `npm install`

## Running / Development

- `ember serve`
- Visit your app at [http://localhost:4200](http://localhost:4200).
- Visit your tests at [http://localhost:4200/tests](http://localhost:4200/tests).

### Code Generators

Make use of the many generators for code, try `ember help generate` for more details

### Running Tests

- `ember test`
- `ember test --server`

### Linting

- `npm run lint`
- `npm run lint:fix`

### Building

- `ember build` (development)
- `ember build --environment production` (production)

### Deploying

Specify what it takes to deploy your app.

## Further Reading / Useful Links

- [ember.js](https://emberjs.com/)
- [ember-cli](https://cli.emberjs.com/release/)
- Development Browser Extensions
- [ember inspector for chrome](https://chrome.google.com/webstore/detail/ember-inspector/bmdblncegkenkacieihfhpjfppoconhi)
- [ember inspector for firefox](https://addons.mozilla.org/en-US/firefox/addon/ember-inspector/)
20 changes: 20 additions & 0 deletions dev-packages/e2e-tests/test-applications/ember-classic/app/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Application from '@ember/application';
import * as Sentry from '@sentry/ember';
import loadInitializers from 'ember-load-initializers';
import Resolver from 'ember-resolver';

import config from './config/environment';

Sentry.init({
replaysSessionSampleRate: 1,
replaysOnErrorSampleRate: 1,
tunnel: `http://localhost:3031/`, // proxy server
});

export default class App extends Application {
public modulePrefix = config.modulePrefix;
public podModulePrefix = config.podModulePrefix;
public Resolver = Resolver;
}

loadInitializers(App, config.modulePrefix);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<a href={{this.href}} class={{if this.isActive 'active'}} {{on 'click' this.onClick}}>
{{yield}}
</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { action } from '@ember/object';
import type RouterService from '@ember/routing/router-service';
import { inject as service } from '@ember/service';
import Component from '@glimmer/component';

interface Args {
route: string;
}

/*
Note: We use this custom component instead of the built-in `<LinkTo>`,
as that is an ember component in older versions, and a glimmer component in newer versions.
Since glimmer components are, as of now, not instrumented, this leads to different test results.
*/
export default class LinkComponent extends Component<Args> {
@service public declare router: RouterService;

public get href(): string {
return this.router.urlFor(this.args.route);
}

public get isActive(): boolean {
return this.router.currentRouteName === this.args.route;
}

@action
public onClick(event: MouseEvent): void {
event.preventDefault();

void this.router.transitionTo(this.args.route);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable ember/no-empty-glimmer-component-classes */
import Component from '@glimmer/component';

export default class SlowLoadingGCList extends Component {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* eslint-disable ember/no-classic-classes */
/* eslint-disable ember/no-classic-components */
import Component from '@ember/component';
import { computed } from '@ember/object';

interface Args {
title?: string;
items: number;
}

export default Component.extend({
tagName: '',

_title: computed('title', function () {
return (this as Args).title || 'Slow Loading List';
}),

rowItems: computed('items', function () {
return new Array((this as Args).items).fill(0).map((_, index) => {
return {
index: index + 1,
};
});
}),
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable ember/no-classic-classes */
/* eslint-disable ember/no-classic-components */
/* eslint-disable ember/require-tagless-components */
import Component from '@ember/component';

export default Component.extend({});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Type declarations for
* import config from './config/environment'
*
* For now these need to be managed by the developer
* since different ember addons can materialize new entries.
*/
declare const config: {
environment: string;
modulePrefix: string;
podModulePrefix: string;
locationType: 'history' | 'hash' | 'none' | 'auto';
rootURL: string;
APP: Record<string, unknown>;
};

export default config;
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { scheduleOnce } from '@ember/runloop';
import { tracked } from '@glimmer/tracking';
import { Promise } from 'rsvp';

export default class IndexController extends Controller {
@tracked public showComponents = false;

@action
public createError(): void {
// @ts-expect-error this is fine
this.nonExistentFunction();
}

@action
public createEmberError(): void {
throw new Error('Whoops, looks like you have an EmberError');
}

@action
public createCaughtEmberError(): void {
try {
throw new Error('Looks like you have a caught EmberError');
} catch (e) {
// do nothing
}
}

@action
public createFetchError(): void {
void fetch('http://doesntexist.example');
}

@action
public createAfterRenderError(): void {
function throwAfterRender(): void {
throw new Error('After Render Error');
}
scheduleOnce('afterRender', null, throwAfterRender);
}

@action
public createRSVPRejection(): Promise<void> {
const promise = new Promise<void>((resolve, reject) => {
reject('Promise rejected');
});
return promise;
}

@action
public createRSVPError(): Promise<void> {
const promise = new Promise<void>(() => {
throw new Error('Error within RSVP Promise');
});
return promise;
}

@action
public toggleShowComponents(): void {
this.showComponents = !this.showComponents;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Controller from '@ember/controller';
import { action } from '@ember/object';
import type RouterService from '@ember/routing/router-service';
import { inject as service } from '@ember/service';

export default class SlowLoadingRouteController extends Controller {
@service public declare router: RouterService;

@action
public back(): void {
void this.router.transitionTo('tracing');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Controller from '@ember/controller';

export default class SlowLoadingRouteController extends Controller {
public slowLoadingTemplateOnlyItems = new Array(2000).fill(0).map((_, index) => index);
}
Loading

0 comments on commit dc2659c

Please sign in to comment.