diff --git a/MIGRATION.md b/MIGRATION.md index eb7121e1..757c2738 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -15,6 +15,16 @@ Short answer: to benefit from fixes and new features, you should upgrade to the Please head to the [CHANGELOG](CHANGELOG.md) for a complete list of changes. +## Migration Script + +For some of the changes, we created a migration script. After installing Spectator v4, just run: + +```bash +$ spectator-migrate +``` + +This will apply some of the migration changes to your `*.spec.ts` files. + ## BREAKING CHANGES :x: Let's first discuss what we changed or removed. You will need to make these changes in order to use Spectator 4. diff --git a/migrate.js b/migrate.js index 9e2baff6..25ff832e 100644 --- a/migrate.js +++ b/migrate.js @@ -1,45 +1,59 @@ -const replace = require('replace-in-file'); -const basePath = `...`; -const files = `${basePath}/**/*.spec.ts`; +#!/usr/bin/env node + +// tslint:disable + +const replace = require("replace-in-file"); const lib = { - files, from: /@netbasal\/spectator/, - to: '@ngneat/spectator' + to: "@ngneat/spectator", }; const componentFactory = { - files, from: /createTestComponentFactory/g, - to: 'createComponentFactory' + to: "createComponentFactory", }; const hostFactory = { - files, from: /createHostComponentFactory/g, - to: 'createHostFactory' + to: "createHostFactory", }; const httpFactory = { - files, from: /createHTTPFactory/g, - to: 'createHttpFactory' + to: "createHttpFactory", }; -const SpectatorWithHost = { - files, +const spectatorWithHost = { from: /SpectatorWithHost/g, - to: 'SpectatorHost' + to: "SpectatorHost", }; -const SpectatorHTTP = { - files, +const spectatorHTTP = { from: /SpectatorHTTP/g, - to: 'SpectatorHttp' + to: "SpectatorHttp", }; -const changes = [lib, componentFactory, hostFactory, httpFactory, SpectatorWithHost, SpectatorHTTP]; +const getDirectiveInstance = { + from: /\.getDirectiveInstance/g, + to: ".queryHost", +}; -changes.forEach(options => { - replace.sync(options); +const changes = [ + lib, + componentFactory, + hostFactory, + httpFactory, + spectatorWithHost, + spectatorHTTP, + getDirectiveInstance +]; + +changes.forEach(({ from, to }) => { + replace.sync({ + files: "**/*.spec.ts", + from, + ignore: "node_modules/**/*", + to, + }); }); diff --git a/package.json b/package.json index 5a739fb3..af900709 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Angular tests made easy", "scripts": { "ng": "ng", - "build": "ng build && npm run build:schematics && npm run copy:schematics && npm run copy:docs", + "build": "ng build && npm run build:schematics && npm run copy:schematics && npm run copy:docs && npm run copy:bin", "build:schematics": "tsc -p projects/spectator/schematics/tsconfig.json", "test": "ng test", "test:jest": "ng run spectator:test-jest", @@ -16,6 +16,7 @@ "precommit": "lint-staged", "contributors:add": "all-contributors add", "contributors:generate": "all-contributors generate", + "copy:bin": "cp migrate.js dist/spectator", "copy:docs": "cp *.md dist/spectator", "copy:schematics": "cp -r projects/spectator/schematics/src/ dist/spectator/schematics", "postbump": "npm run build", @@ -23,7 +24,8 @@ }, "dependencies": { "@testing-library/dom": "6.1.0", - "jquery": "3.4.1" + "jquery": "3.4.1", + "replace-in-file": "^4.1.3" }, "devDependencies": { "@angular-builders/jest": "^8.0.4", diff --git a/projects/spectator/ng-package.json b/projects/spectator/ng-package.json index f40a78de..e3aac770 100644 --- a/projects/spectator/ng-package.json +++ b/projects/spectator/ng-package.json @@ -7,6 +7,7 @@ "whitelistedNonPeerDependencies": [ "@testing-library/dom", "jquery", - "schematics-utilities" + "schematics-utilities", + "replace-in-file" ] -} \ No newline at end of file +} diff --git a/projects/spectator/package.json b/projects/spectator/package.json index 48c18dbe..0567e1fe 100644 --- a/projects/spectator/package.json +++ b/projects/spectator/package.json @@ -25,7 +25,8 @@ "dependencies": { "@testing-library/dom": "6.1.0", "jquery": "3.4.1", - "schematics-utilities": "^1.1.1" + "schematics-utilities": "^1.1.1", + "replace-in-file": "^4.1.3" }, "peerDependencies": { "@angular/common": "^8.0.0", @@ -33,5 +34,8 @@ "@angular/router": "^8.0.0", "typescript": ">= 2.8.0" }, + "bin": { + "spectator-migrate": "./migrate.js" + }, "schematics": "./schematics/collection.json" -} \ No newline at end of file +}