Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

export default {
pre() {
},
// This hook is used to manipulate the webpack configuration
config(cfg) {
return cfg;
},
@meDavid
meDavid / ng-ts-dummy-transformer.ts
Created March 18, 2019 15:11
A dummy Typescript transformer that logs the filenames to the console
import * as ts from 'typescript';
export const dummyTransformer = <T extends ts.Node>(context: ts.TransformationContext) => {
return (rootNode: ts.SourceFile) => {
console.log('Transforming file: ' + rootNode.fileName);
function visit(node: ts.Node): ts.Node {
return ts.visitEachChild(node, visit, context);
}
return ts.visitNode(rootNode, visit);
};
@meDavid
meDavid / ng-ts-register-transformer.ts
Last active March 18, 2019 15:05
Example ngx-build-plus plugin to register a typescript transformer
import { dummyTransformer } from './ng-ts-dummy-transformer';
import { AngularCompilerPlugin } from '@ngtools/webpack';
function findAngularCompilerPlugin(webpackCfg): AngularCompilerPlugin | null {
return webpackCfg.plugins.find(plugin => plugin instanceof AngularCompilerPlugin);
}
// The AngularCompilerPlugin has nog public API to add transformations, user private API _transformers instead.
function addTransformerToAngularCompilerPlugin(acp, transformer): void {
acp._transformers = [transformer, ...acp._transformers];
@meDavid
meDavid / spec-private-api.ts
Last active January 14, 2019 13:45
cypress angular unittest with private APIs
import { ɵrenderComponent as renderComponent, ɵcompileComponent as compileComponent} from '@angular/core';
import '@angular/compiler';
import 'zone.js';
import { AppComponent } from '../../src/app/app.component';
/* eslint-env mocha */
/* global cy */
describe('AppComponent', () => {
beforeEach(() => {
const html = `
// Copy of https://github.com/bahmutov/cypress-angular-unit-test/blob/master/cypress/plugins/cy-ts-preprocessor.js
const wp = require('@cypress/webpack-preprocessor')
const webpackOptions = {
resolve: {
extensions: ['.ts', '.js']
},
module: {
rules: [
{
@meDavid
meDavid / tsconfig.json
Created January 11, 2019 10:04
Minimal Cypress tsconfig file
{
"include": [
"integration/*.ts",
"../node_modules/cypress"
],
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"skipLibCheck": true
}
@meDavid
meDavid / package.json
Created January 11, 2019 09:55
Cypress package.json scripts
{
.....
"scripts": {
...
"cy:open": "cypress open",
"cy:run": "cypress run"
},
....
}