From 5da50f3a4789f21e48e44a79c0dc879118879c23 Mon Sep 17 00:00:00 2001
From: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com>
Date: Mon, 13 May 2019 22:19:27 +0200
Subject: [PATCH] fix: don't include jest-utils in main package (#15)

---
 angular.json                                  | 27 ++++++++++++++++++
 package.json                                  |  3 +-
 projects/jest-utils/ng-package.json           |  8 ++++++
 projects/jest-utils/ng-package.prod.json      |  8 ++++++
 projects/jest-utils/package.json              | 28 +++++++++++++++++++
 .../src/lib/configure-test-suite.ts           | 23 +++++++++++++++
 projects/jest-utils/src/lib/index.ts          |  1 +
 projects/jest-utils/src/public_api.ts         |  5 ++++
 projects/jest-utils/tsconfig.lib.json         | 27 ++++++++++++++++++
 projects/jest-utils/tslint.json               |  3 ++
 projects/testing-library/ng-package.json      |  2 +-
 .../src/lib/testing-library.ts                |  3 +-
 projects/testing-library/src/public_api.ts    |  1 -
 src/app/app.component.spec.ts                 |  3 +-
 14 files changed, 136 insertions(+), 6 deletions(-)
 create mode 100644 projects/jest-utils/ng-package.json
 create mode 100644 projects/jest-utils/ng-package.prod.json
 create mode 100644 projects/jest-utils/package.json
 create mode 100644 projects/jest-utils/src/lib/configure-test-suite.ts
 create mode 100644 projects/jest-utils/src/lib/index.ts
 create mode 100644 projects/jest-utils/src/public_api.ts
 create mode 100644 projects/jest-utils/tsconfig.lib.json
 create mode 100644 projects/jest-utils/tslint.json

diff --git a/angular.json b/angular.json
index 333299e1..273e0a17 100644
--- a/angular.json
+++ b/angular.json
@@ -94,6 +94,33 @@
           }
         }
       }
+    },
+    "jest-utils": {
+      "root": "projects/jest-utils",
+      "sourceRoot": "projects/jest-utils/src",
+      "projectType": "library",
+      "prefix": "lib",
+      "architect": {
+        "build": {
+          "builder": "@angular-devkit/build-ng-packagr:build",
+          "options": {
+            "tsConfig": "projects/jest-utils/tsconfig.lib.json",
+            "project": "projects/jest-utils/ng-package.json"
+          },
+          "configurations": {
+            "production": {
+              "project": "projects/jest-utils/ng-package.prod.json"
+            }
+          }
+        },
+        "lint": {
+          "builder": "@angular-devkit/build-angular:tslint",
+          "options": {
+            "tsConfig": ["projects/jest-utils/tsconfig.lib.json", "./tsconfig.spec.json"],
+            "exclude": ["**/node_modules/**"]
+          }
+        }
+      }
     }
   },
   "defaultProject": "testing-library-app"
diff --git a/package.json b/package.json
index e37e5981..8fd968ea 100644
--- a/package.json
+++ b/package.json
@@ -5,8 +5,9 @@
     "ng": "ng",
     "start": "ng serve",
     "prebuild": "rimraf dist",
-    "build": "npm run build:library && npm run build:migrations && npm run build:readme",
+    "build": "npm run build:library && npm run build:library:jest-utils && npm run build:migrations && npm run build:readme",
     "build:library": "ng build --prod testing-library",
+    "build:library:jest-utils": "ng build --prod jest-utils",
     "build:migrations": "tsc -p ./projects/testing-library/migrations/tsconfig.migrations.json && cp ./projects/testing-library/migrations/migration.json ./dist/@angular-extensions/testing-library/migrations",
     "build:readme": "cp ./README.md ./dist/@angular-extensions/testing-library",
     "test": "jest --config ./projects/jest.lib.config.js",
diff --git a/projects/jest-utils/ng-package.json b/projects/jest-utils/ng-package.json
new file mode 100644
index 00000000..8aceba58
--- /dev/null
+++ b/projects/jest-utils/ng-package.json
@@ -0,0 +1,8 @@
+{
+  "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
+  "dest": "../../@angular-extensions/testing-library/jest-utils",
+  "deleteDestPath": false,
+  "lib": {
+    "entryFile": "src/public_api.ts"
+  }
+}
diff --git a/projects/jest-utils/ng-package.prod.json b/projects/jest-utils/ng-package.prod.json
new file mode 100644
index 00000000..cc161cf1
--- /dev/null
+++ b/projects/jest-utils/ng-package.prod.json
@@ -0,0 +1,8 @@
+{
+  "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
+  "dest": "../../dist/@angular-extensions/testing-library/jest-utils",
+  "deleteDestPath": false,
+  "lib": {
+    "entryFile": "src/public_api.ts"
+  }
+}
diff --git a/projects/jest-utils/package.json b/projects/jest-utils/package.json
new file mode 100644
index 00000000..3aecfeb8
--- /dev/null
+++ b/projects/jest-utils/package.json
@@ -0,0 +1,28 @@
+{
+  "name": "@angular-extensions/testing-library/jest-utils",
+  "version": "0.0.0-semantically-released",
+  "description": "Test your Angular components with the dom-testing-library",
+  "repository": {
+    "type": "git",
+    "url": "git+https://github.com/angular-extensions/testing-library.git"
+  },
+  "keywords": [
+    "angular",
+    "ngx",
+    "ng",
+    "typescript",
+    "angular2",
+    "test",
+    "dom-testing-library",
+    "angular-extensions"
+  ],
+  "author": "Tim Deschryver",
+  "license": "MIT",
+  "bugs": {
+    "url": "https://github.com/angular-extensions/testing-library/issues"
+  },
+  "homepage": "https://github.com/angular-extensions/testing-library#readme",
+  "publishConfig": {
+    "access": "public"
+  }
+}
diff --git a/projects/jest-utils/src/lib/configure-test-suite.ts b/projects/jest-utils/src/lib/configure-test-suite.ts
new file mode 100644
index 00000000..f6ff3143
--- /dev/null
+++ b/projects/jest-utils/src/lib/configure-test-suite.ts
@@ -0,0 +1,23 @@
+import { TestBed, getTestBed, ComponentFixture } from '@angular/core/testing';
+import 'jest';
+
+// Ref: https://github.com/angular/angular/issues/12409
+export function configureJestSetup() {
+  const testBedApi: any = getTestBed();
+  const originReset = TestBed.resetTestingModule;
+
+  beforeAll(() => {
+    TestBed.resetTestingModule();
+    TestBed.resetTestingModule = () => TestBed;
+  });
+
+  afterEach(() => {
+    testBedApi._activeFixtures.forEach((fixture: ComponentFixture<any>) => fixture.destroy());
+    testBedApi._instantiated = false;
+  });
+
+  afterAll(() => {
+    TestBed.resetTestingModule = originReset;
+    TestBed.resetTestingModule();
+  });
+}
diff --git a/projects/jest-utils/src/lib/index.ts b/projects/jest-utils/src/lib/index.ts
new file mode 100644
index 00000000..ea63e26e
--- /dev/null
+++ b/projects/jest-utils/src/lib/index.ts
@@ -0,0 +1 @@
+export * from './configure-test-suite';
diff --git a/projects/jest-utils/src/public_api.ts b/projects/jest-utils/src/public_api.ts
new file mode 100644
index 00000000..a0e30064
--- /dev/null
+++ b/projects/jest-utils/src/public_api.ts
@@ -0,0 +1,5 @@
+/*
+ * Public API Surface of testing-library
+ */
+
+export * from './lib';
diff --git a/projects/jest-utils/tsconfig.lib.json b/projects/jest-utils/tsconfig.lib.json
new file mode 100644
index 00000000..8be8cbcd
--- /dev/null
+++ b/projects/jest-utils/tsconfig.lib.json
@@ -0,0 +1,27 @@
+{
+  "extends": "../../tsconfig.json",
+  "compilerOptions": {
+    "outDir": "../../out-tsc/lib",
+    "target": "es2015",
+    "module": "es2015",
+    "moduleResolution": "node",
+    "declaration": true,
+    "sourceMap": true,
+    "inlineSources": true,
+    "emitDecoratorMetadata": true,
+    "experimentalDecorators": true,
+    "importHelpers": true,
+    "types": [],
+    "lib": ["dom", "es2015"]
+  },
+  "angularCompilerOptions": {
+    "annotateForClosureCompiler": true,
+    "skipTemplateCodegen": true,
+    "strictMetadataEmit": true,
+    "fullTemplateTypeCheck": true,
+    "strictInjectionParameters": true,
+    "flatModuleId": "AUTOGENERATED",
+    "flatModuleOutFile": "AUTOGENERATED"
+  },
+  "exclude": ["src/test.ts", "**/*.spec.ts"]
+}
diff --git a/projects/jest-utils/tslint.json b/projects/jest-utils/tslint.json
new file mode 100644
index 00000000..0946f209
--- /dev/null
+++ b/projects/jest-utils/tslint.json
@@ -0,0 +1,3 @@
+{
+  "extends": "../../tslint.json"
+}
diff --git a/projects/testing-library/ng-package.json b/projects/testing-library/ng-package.json
index 15d0496b..a8680a40 100644
--- a/projects/testing-library/ng-package.json
+++ b/projects/testing-library/ng-package.json
@@ -1,6 +1,6 @@
 {
   "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
-  "dest": "../../@angular-extensions/testing-library",
+  "dest": "../../dist/@angular-extensions/testing-library",
   "deleteDestPath": false,
   "lib": {
     "entryFile": "src/public_api.ts"
diff --git a/projects/testing-library/src/lib/testing-library.ts b/projects/testing-library/src/lib/testing-library.ts
index 264d4df5..9b04b909 100644
--- a/projects/testing-library/src/lib/testing-library.ts
+++ b/projects/testing-library/src/lib/testing-library.ts
@@ -1,9 +1,8 @@
 import { Component, OnInit, ElementRef, Type, DebugElement } from '@angular/core';
+import { By } from '@angular/platform-browser';
 import { TestBed, ComponentFixture } from '@angular/core/testing';
 import { getQueriesForElement, prettyDOM, fireEvent, FireObject, FireFunction } from 'dom-testing-library';
-
 import { RenderResult, RenderOptions } from './models';
-import { By } from '@angular/platform-browser';
 
 @Component({ selector: 'wrapper-component', template: '' })
 class WrapperComponent implements OnInit {
diff --git a/projects/testing-library/src/public_api.ts b/projects/testing-library/src/public_api.ts
index 2f96008f..e9c2f9a4 100644
--- a/projects/testing-library/src/public_api.ts
+++ b/projects/testing-library/src/public_api.ts
@@ -4,5 +4,4 @@
 
 export * from './lib/models';
 export * from './lib/testing-library';
-export * from './jest-utils';
 export * from 'dom-testing-library';
diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts
index 477d6729..d36ae40b 100644
--- a/src/app/app.component.spec.ts
+++ b/src/app/app.component.spec.ts
@@ -1,5 +1,6 @@
 import { AppComponent } from './app.component';
-import { render, configureJestSetup } from '@angular-extensions/testing-library';
+import { render } from '@angular-extensions/testing-library';
+import { configureJestSetup } from '@angular-extensions/testing-library/jest-utils';
 
 configureJestSetup();