This repository has been archived by the owner on Oct 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
289 additions
and
139 deletions.
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,75 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: {} | ||
|
||
concurrency: | ||
# Group concurrency on workflow, then: | ||
# - Is merge run? Group on branch name (`refs/heads/main`) | ||
# - Is pull request? Group on pull request branch name, for example `feat/add-awesome-feature` | ||
group: >- | ||
${{ github.workflow }}-${{ | ||
github.event_name == 'push' | ||
&& github.ref | ||
|| github.head_ref | ||
}} | ||
# Run merge workflows in sequence to prevent parallel deployments and releases | ||
# Cancel stale pull request runs in progress for the same branch | ||
cancel-in-progress: ${{ github.event_name != 'push' }} | ||
|
||
env: | ||
NODE_OPTIONS: --max-old-space-size=6144 | ||
|
||
jobs: | ||
# We're using Nx Cloud for Distributed Task Execution | ||
# Reference: https://nx.dev/using-nx/dte | ||
# | ||
# The coordinator outputs the combination of task outputs from the agents, | ||
# both terminal and file outputs | ||
dte_coordinator: | ||
name: DTE Coordinator | ||
uses: nrwl/ci/.github/workflows/[email protected] | ||
with: | ||
# Commands run in parallel on this DTE coordinator | ||
parallel-commands: | | ||
yarn nx-cloud record -- yarn nx workspace-lint | ||
yarn nx-cloud record -- yarn nx format:check | ||
# Commands distributed between DTE agents | ||
# Distribution strategy for 2 vCPUs per hosted runner (GitHub Free): | ||
# lint: 2 tasks assigned at a time, 1 task per vCPU | ||
# test: 1 task assigned at a time with 2 parallel processes, 1 process per vCPU | ||
# build: 2 tasks assigned at a time, 1 task per vCPU | ||
# e2e: 1 task assigned at a time, 1 task total | ||
parallel-commands-on-agents: | | ||
yarn nx affected --target=lint --parallel=2 | ||
yarn nx affected --target=test --parallel=1 --ci --maxWorkers=2 | ||
yarn nx affected --target=build --parallel=2 | ||
yarn nx affected --target=e2e --exclude=lumberjack-app-e2e --parallel=1 | ||
# Commands run sequentially on this DTE coordinator after parallel jobs | ||
# For the end-to-end test of our application, we use the output bundle | ||
final-commands: | | ||
NX_CLOUD_DISTRIBUTED_EXECUTION=false yarn nx run lumberjack-app:use-lumberjack-bundle | ||
yarn nx e2e lumberjack-app-e2e | ||
# We're using Nx Cloud for Distributed Task Execution | ||
# Reference: https://nx.dev/using-nx/dte | ||
# | ||
# Agents receive tasks to execute in bulk whenever they are ready or have | ||
# finished their previous tasks | ||
dte_agents: | ||
name: DTE Agents | ||
uses: nrwl/ci/.github/workflows/[email protected] | ||
with: | ||
# The Free GitHub plan has a limit of 20 concurrent jobs on Ubuntu images | ||
# Reference: https://docs.github.com/en/actions/learn-github-actions/usage-limits-billing-and-administration | ||
# If we need to, we can optimize for 2 simultaneous workflow runs: | ||
# 2 x 1 main job = 2 concurrent jobs | ||
# 2 x 9 agent jobs = 18 concurrent jobs | ||
# Total = 20 concurrent jobs | ||
# | ||
# However, we don't have many projects or targets in this workspace, so we | ||
# lower the number of agents to reduce spent compute time. | ||
number-of-agents: 4 |
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
23 changes: 23 additions & 0 deletions
23
apps/lumberjack-app-e2e/src/integration/console-driver.spec.ts
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 @@ | ||
describe('Console log driver', () => { | ||
function visit() { | ||
cy.visit('/', { | ||
onBeforeLoad(win): void { | ||
cy.stub(win.console, 'error').as('consoleError'); | ||
cy.stub(win.console, 'info').as('consoleInfo'); | ||
}, | ||
}); | ||
} | ||
it('logs a greeting info message', () => { | ||
visit(); | ||
|
||
cy.get('@consoleInfo').should('have.been.calledWith', 'info [Forest App] Hello, Forest!'); | ||
}); | ||
|
||
it('logs a critical forest fire message after 2 seconds', () => { | ||
cy.clock(); | ||
visit(); | ||
|
||
cy.tick(2000); | ||
cy.get('@consoleError').should('have.been.calledWith', 'critical [Forest App] The forest is on fire!'); | ||
}); | ||
}); |
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
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 |
---|---|---|
@@ -1,10 +1,28 @@ | ||
import { Component } from '@angular/core'; | ||
import { Component, OnInit, OnDestroy } from '@angular/core'; | ||
import { Subscription } from 'rxjs'; | ||
|
||
import { AppLogger } from './app.logger'; | ||
import { ForestService } from './forest.service'; | ||
|
||
@Component({ | ||
selector: 'app-root', | ||
templateUrl: './app.component.html', | ||
styleUrls: ['./app.component.scss'], | ||
}) | ||
export class AppComponent { | ||
export class AppComponent implements OnInit, OnDestroy { | ||
#subscriptions = new Subscription(); | ||
|
||
title = 'lumberjack-app'; | ||
|
||
constructor(private logger: AppLogger, private forest: ForestService) {} | ||
|
||
ngOnInit(): void { | ||
this.logger.helloForest(); | ||
|
||
this.#subscriptions.add(this.forest.fire$.subscribe(() => this.logger.forestOnFire())); | ||
} | ||
|
||
ngOnDestroy(): void { | ||
this.#subscriptions.unsubscribe(); | ||
} | ||
} |
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,14 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
import { ScopedLumberjackLogger } from '@ngworker/lumberjack'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class AppLogger extends ScopedLumberjackLogger { | ||
scope = 'Forest App'; | ||
|
||
forestOnFire = this.createCriticalLogger('The forest is on fire!').build(); | ||
|
||
helloForest = this.createInfoLogger('Hello, Forest!').build(); | ||
} |
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 |
---|---|---|
@@ -1,13 +1,28 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { LumberjackLog, LumberjackModule, LumberjackOptions } from '@ngworker/lumberjack'; | ||
import { LumberjackConsoleDriverModule } from '@ngworker/lumberjack/console-driver'; | ||
|
||
import { AppComponent } from './app.component'; | ||
import { NxWelcomeComponent } from './nx-welcome.component'; | ||
|
||
const cypressLumberjackOptions: LumberjackOptions = { | ||
format({ level, message, scope }: LumberjackLog): string { | ||
const scopeLog = scope ? ` [${scope}]` : ''; | ||
|
||
// We leave out the `createdAt` timestamp to avoid having to construct | ||
// timestamps in end-to-end tests | ||
return `${level}${scopeLog} ${message}`; | ||
}, | ||
}; | ||
|
||
@NgModule({ | ||
declarations: [AppComponent, NxWelcomeComponent], | ||
imports: [BrowserModule], | ||
providers: [], | ||
bootstrap: [AppComponent], | ||
declarations: [AppComponent, NxWelcomeComponent], | ||
imports: [ | ||
BrowserModule, | ||
LumberjackModule.forRoot('Cypress' in window ? cypressLumberjackOptions : undefined), | ||
LumberjackConsoleDriverModule.forRoot(), | ||
], | ||
}) | ||
export class AppModule {} |
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,19 @@ | ||
import { Injectable, OnDestroy } from '@angular/core'; | ||
import { ReplaySubject } from 'rxjs'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class ForestService implements OnDestroy { | ||
#fire$ = new ReplaySubject<void>(1); | ||
|
||
fire$ = this.#fire$.asObservable(); | ||
|
||
constructor() { | ||
setTimeout(() => this.#fire$.next(), 2000); | ||
} | ||
|
||
ngOnDestroy(): void { | ||
this.#fire$.complete(); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,12 +1 @@ | ||
# Internal test utilities for the console log driver | ||
|
||
## Buildable library | ||
|
||
This library is buildable because Lumberjack's tests depend on it. Lumberjack is a publishable library and since buildable and publishable libraries cannot depend on non-buildable libraries, this library has to be buildable. Because of this, we have added a `build` target to this library. | ||
|
||
The following files are related to the `build` target: | ||
|
||
- `ng-package.json` | ||
- `package.json` | ||
- `project.json` | ||
- `tsconfig.lib.prod.json` |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
7 changes: 0 additions & 7 deletions
7
libs/internal/console-driver/test-util/tsconfig.lib.prod.json
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.