Skip to content

Commit

Permalink
feat: add migration CLI script
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkluijk committed Aug 26, 2019
1 parent 4175b30 commit 238cff5
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 26 deletions.
10 changes: 10 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
54 changes: 34 additions & 20 deletions migrate.js
Original file line number Diff line number Diff line change
@@ -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,
});
});
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -16,14 +16,16 @@
"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",
"release": "cd projects/spectator && standard-version --infile ../../CHANGELOG.md"
},
"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",
Expand Down
5 changes: 3 additions & 2 deletions projects/spectator/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"whitelistedNonPeerDependencies": [
"@testing-library/dom",
"jquery",
"schematics-utilities"
"schematics-utilities",
"replace-in-file"
]
}
}
8 changes: 6 additions & 2 deletions projects/spectator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@
"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",
"@angular/core": "^8.0.0",
"@angular/router": "^8.0.0",
"typescript": ">= 2.8.0"
},
"bin": {
"spectator-migrate": "./migrate.js"
},
"schematics": "./schematics/collection.json"
}
}

0 comments on commit 238cff5

Please sign in to comment.