This repository has been archived by the owner on Dec 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ionic-react): create migration for @testing-library/cypress (#246)
- Loading branch information
1 parent
2d228ec
commit e28c728
Showing
9 changed files
with
233 additions
and
79 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
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
105 changes: 105 additions & 0 deletions
105
...t/src/migrations/update-3-1-0/update-testing-library-cypress-tsconfig-types-3-1-0.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,105 @@ | ||
import { Tree } from '@angular-devkit/schematics'; | ||
import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; | ||
import { readJsonInTree, serializeJson } from '@nrwl/workspace'; | ||
import { createEmptyWorkspace } from '@nrwl/workspace/testing'; | ||
import * as path from 'path'; | ||
|
||
describe('Update 3.1.0', () => { | ||
let initialTree: Tree; | ||
let schematicRunner: SchematicTestRunner; | ||
|
||
beforeEach(async () => { | ||
initialTree = createEmptyWorkspace(Tree.empty()); | ||
|
||
schematicRunner = new SchematicTestRunner( | ||
'@nxtend/ionic-react', | ||
path.join(__dirname, '../../../migrations.json') | ||
); | ||
|
||
initialTree.overwrite( | ||
'package.json', | ||
serializeJson({ | ||
devDependencies: { | ||
'@nxtend/ionic-react': '0.0.0', | ||
}, | ||
}) | ||
); | ||
|
||
initialTree.overwrite( | ||
'workspace.json', | ||
serializeJson({ | ||
projects: { | ||
'app-one': { | ||
root: 'apps/app-one', | ||
architect: { | ||
build: { | ||
options: { | ||
webpackConfig: '@nxtend/ionic-react/plugins/webpack', | ||
}, | ||
}, | ||
}, | ||
}, | ||
'app-one-e2e': { | ||
root: 'apps/app-one-e2e', | ||
architect: {}, | ||
}, | ||
}, | ||
}) | ||
); | ||
|
||
initialTree.create( | ||
'apps/app-one-e2e/tsconfig.json', | ||
serializeJson({ | ||
extends: '../../tsconfig.base.json', | ||
files: [], | ||
include: [], | ||
references: [ | ||
{ | ||
path: './tsconfig.e2e.json', | ||
}, | ||
], | ||
compilerOptions: { | ||
types: ['@types/testing-library__cypress'], | ||
}, | ||
}) | ||
); | ||
|
||
initialTree.create( | ||
'apps/app-one-e2e/tsconfig.e2e.json', | ||
serializeJson({ | ||
extends: './tsconfig.json', | ||
compilerOptions: { | ||
sourceMap: false, | ||
outDir: '../../dist/out-tsc', | ||
allowJs: true, | ||
types: ['cypress', 'node'], | ||
}, | ||
include: ['src/**/*.ts', 'src/**/*.js'], | ||
}) | ||
); | ||
}); | ||
|
||
it(`should @testing-library/cypress tsconfig types`, async () => { | ||
const result = await schematicRunner | ||
.runSchematicAsync( | ||
'update-testing-library-cypress-tsconfig-types-3.1.0', | ||
{}, | ||
initialTree | ||
) | ||
.toPromise(); | ||
|
||
const appOneTsconfig = readJsonInTree( | ||
result, | ||
'apps/app-one-e2e/tsconfig.json' | ||
); | ||
const appOneTsconfigE2e = readJsonInTree( | ||
result, | ||
'apps/app-one-e2e/tsconfig.e2e.json' | ||
); | ||
|
||
expect(appOneTsconfig.compilerOptions.types).toEqual([]); | ||
expect(appOneTsconfigE2e.compilerOptions.types).toContain( | ||
'@testing-library/cypress' | ||
); | ||
}); | ||
}); |
108 changes: 108 additions & 0 deletions
108
...-react/src/migrations/update-3-1-0/update-testing-library-cypress-tsconfig-types-3-1-0.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,108 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { chain, Rule, Tree } from '@angular-devkit/schematics'; | ||
import { formatFiles, readJsonInTree, updateJsonInTree } from '@nrwl/workspace'; | ||
import * as path from 'path'; | ||
|
||
function getTsconfigFilePaths( | ||
host: Tree | ||
): { tsconfigFilePaths: string[]; tsconfigE2eFilePaths: string[] } { | ||
const tsconfigFilePaths = []; | ||
const tsconfigE2eFilePaths = []; | ||
|
||
const workspaceJson = readJsonInTree(host, 'workspace.json'); | ||
Object.values<any>(workspaceJson.projects).forEach((project) => { | ||
Object.values<any>(project.architect).forEach((target) => { | ||
if ( | ||
target.options?.webpackConfig !== '@nxtend/ionic-react/plugins/webpack' | ||
) { | ||
return; | ||
} | ||
|
||
const e2eProjectName = Object.keys(workspaceJson.projects).find( | ||
(key) => workspaceJson.projects[key] === project | ||
); | ||
|
||
const e2eProject = workspaceJson.projects[`${e2eProjectName}-e2e`]; | ||
|
||
if ( | ||
host.exists(`${e2eProject.root}/tsconfig.e2e.json`) && | ||
host.exists(`${e2eProject.root}/tsconfig.json`) | ||
) { | ||
tsconfigFilePaths.push(path.join(e2eProject.root, 'tsconfig.json')); | ||
tsconfigE2eFilePaths.push(`${e2eProject.root}/tsconfig.e2e.json`); | ||
} | ||
}); | ||
}); | ||
|
||
return { tsconfigFilePaths, tsconfigE2eFilePaths }; | ||
} | ||
|
||
function updateTsconfigFilePaths(tsconfigFilePaths: string[]): Rule[] { | ||
const rules: Rule[] = []; | ||
|
||
tsconfigFilePaths.forEach((tsconfigFilePath) => { | ||
rules.push( | ||
updateJsonInTree(tsconfigFilePath, (json) => { | ||
if (json.compilerOptions?.types) { | ||
const index = json.compilerOptions.types.indexOf( | ||
'@types/testing-library__cypress' | ||
); | ||
|
||
if (index !== -1) { | ||
json.compilerOptions.types.splice(index, 1); | ||
} | ||
} | ||
|
||
return json; | ||
}) | ||
); | ||
}); | ||
|
||
return rules; | ||
} | ||
|
||
function updateTsconfigE2eFilePaths(tsconfigE2eFilePaths: string[]): Rule[] { | ||
const rules: Rule[] = []; | ||
|
||
tsconfigE2eFilePaths.forEach((tsconfigFilePath) => { | ||
rules.push( | ||
updateJsonInTree(tsconfigFilePath, (json) => { | ||
if (!json.compilerOptions) { | ||
json.compilerOptions = {}; | ||
} | ||
|
||
if (!json.compilerOptions.types) { | ||
json.compilerOptions.types = []; | ||
} | ||
|
||
json.compilerOptions.types.push('@testing-library/cypress'); | ||
|
||
return json; | ||
}) | ||
); | ||
}); | ||
|
||
return rules; | ||
} | ||
|
||
function updateCypressTsconfigTypes(): Rule { | ||
return (host: Tree) => { | ||
let rules: Rule[] = []; | ||
const { devDependencies } = readJsonInTree(host, 'package.json'); | ||
|
||
if (devDependencies && devDependencies['@nxtend/ionic-react']) { | ||
const { tsconfigFilePaths, tsconfigE2eFilePaths } = getTsconfigFilePaths( | ||
host | ||
); | ||
|
||
rules = updateTsconfigFilePaths(tsconfigFilePaths); | ||
rules = [...rules, ...updateTsconfigE2eFilePaths(tsconfigE2eFilePaths)]; | ||
} | ||
|
||
return chain(rules); | ||
}; | ||
} | ||
|
||
export default function update(): Rule { | ||
return chain([updateCypressTsconfigTypes(), formatFiles()]); | ||
} |
39 changes: 0 additions & 39 deletions
39
packages/ionic-react/src/migrations/update-3-1-0/upgrade-ionic-3-1-0.spec.ts
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
packages/ionic-react/src/migrations/update-3-1-0/upgrade-ionic-3-1-0.ts
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
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