Skip to content

Commit

Permalink
fix: fix test paths
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherPHolder committed Jun 19, 2023
1 parent a095061 commit f0cd459
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
27 changes: 13 additions & 14 deletions packages/nx-plugin/src/generators/init/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ describe('init generator', () => {
}
);
normalizedOptions = normalizeOptions(appTree, baseOptions);
writeJson(appTree, join(normalizedOptions.projectRoot, '.user-flowrc.json'), {});
writeJson(appTree, join(normalizedOptions.projectRoot, 'package.json'), {
writeJson(appTree, join('package.json'), {
dependencies: {},
devDependencies: {}
})
writeJson(appTree, join(appTree.root, 'nx.json'), {
writeJson(appTree, join('nx.json'), {
"extends": "nx/presets/core.json",
"tasksRunnerOptions": {
"default": {
Expand All @@ -61,50 +60,50 @@ describe('init generator', () => {
}
}
})
writeJson(appTree, join(normalizedOptions.projectRoot, '.user-flowrc.json'), {});
});

it('should run successfully', async () => {
await generator(appTree, baseOptions);
const config = readProjectConfiguration(appTree, PROJECT_NAME);
expect(config).toBeDefined();
const fn = () => generator(appTree, baseOptions);
await expect(fn()).resolves.toBe(void 0);
});


it('should add user-flow dependency if missing', async () => {
await generator(appTree, baseOptions);
const packageJson = readJson(appTree, join(normalizedOptions.projectRoot, 'package.json'));
const packageJson = readJson(appTree, 'package.json');
expect(packageJson.devDependencies[NPM_NAME]).toBe('^0.19.0');
});

it('should update user-flow dependency if existing', async () => {
updateJson(appTree, join(normalizedOptions.projectRoot, 'package.json'), (json) => {
updateJson(appTree, 'package.json', (json) => {
json.devDependencies[NPM_NAME] = '^1.0.0';
json.devDependencies[PLUGIN_NAME] = '^0.0.0-alpha';
return json;
});
await generator(appTree, baseOptions);
const packageJson = readJson(appTree, join(normalizedOptions.projectRoot, 'package.json'),);
const packageJson = readJson(appTree, 'package.json');
expect(packageJson.devDependencies[NPM_NAME]).toBe('^0.19.0');
expect(packageJson.devDependencies[PLUGIN_NAME]).toBe('^0.0.0');
});

it('should not change dep version if skip option is turned on', async () => {
updateJson(appTree, join(normalizedOptions.projectRoot, 'package.json'), (json) => {
updateJson(appTree, 'package.json', (json) => {
json.devDependencies[NPM_NAME] = '^1.0.0';
json.devDependencies[PLUGIN_NAME] = '^0.0.0';
return json;
});
const oldPackageJson = readJson(appTree, join(normalizedOptions.projectRoot, 'package.json'),);
const oldPackageJson = readJson(appTree, 'package.json');
expect(oldPackageJson.devDependencies[NPM_NAME]).toBe('^1.0.0');
expect(oldPackageJson.devDependencies[PLUGIN_NAME]).toBe('^0.0.0');
await generator(appTree, {...baseOptions, skipPackageJson: true});
const packageJson = readJson(appTree, join(normalizedOptions.projectRoot, 'package.json'),);
const packageJson = readJson(appTree, 'package.json');
expect(packageJson.devDependencies[NPM_NAME]).toBe('^1.0.0');
expect(packageJson.devDependencies[PLUGIN_NAME]).toBe('^0.0.0');
});

it('should update nx.json cacheableOperations if tasksRunnerOptions exists', async () => {
const nxJsonPath = join(appTree.root, 'nx.json');
const nxJsonPath = join('nx.json');
let nxJson = readJson(appTree, nxJsonPath);
expect(nxJson.tasksRunnerOptions).toBeDefined();
expect(nxJson.tasksRunnerOptions.default.options.cacheableOperations.includes('user-flow')).toBeFalsy();
Expand All @@ -114,7 +113,7 @@ describe('init generator', () => {
});

it('should not update nx.json cacheableOperations if tasksRunnerOptions not exists', async () => {
const nxJsonPath = join(appTree.root, 'nx.json');
const nxJsonPath = join('nx.json');
updateJson(appTree, nxJsonPath, (json) => {
delete json.tasksRunnerOptions;
return json;
Expand Down
6 changes: 3 additions & 3 deletions packages/nx-plugin/src/generators/init/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import {InitGeneratorSchema} from './schema';
import {normalizeOptions, updateDependencies, updateNxJson} from "./utils";

export default async function userFlowInitGenerator(tree: Tree, options: InitGeneratorSchema) {
const normalizedOptions = normalizeOptions(tree, options);
//const normalizedOptions = normalizeOptions(tree, options);

if (options.skipPackageJson === false) {
logger.log('Adding packages:');
updateDependencies(tree, normalizedOptions);
updateDependencies(tree);
logger.log('Adding nx config:');
updateNxJson(tree, normalizedOptions);
updateNxJson(tree);
} else {
logger.log('Skip adding packages');
}
Expand Down
12 changes: 6 additions & 6 deletions packages/nx-plugin/src/generators/init/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {getWorkspaceLayout, Tree, updateJson} from "@nrwl/devkit";
import { getWorkspaceLayout, readProjectConfiguration, Tree, updateJson } from '@nrwl/devkit';
import {join} from "path";
import {NormalizedSchema} from "./types";
import {InitGeneratorSchema} from "./schema";
Expand All @@ -8,7 +8,7 @@ import {DEFAULT_TARGET_NAME} from "../target/constants";
export function normalizeOptions(tree: Tree, options?: InitGeneratorSchema): NormalizedSchema {

const projectName = options.projectName;
const projectRoot = `${getWorkspaceLayout(tree).libsDir}/${projectName}`;
const projectRoot = readProjectConfiguration(tree, options.projectName).root;

return {
...options,
Expand All @@ -17,8 +17,8 @@ export function normalizeOptions(tree: Tree, options?: InitGeneratorSchema): Nor
};
}

export function updateDependencies(tree: Tree, options: NormalizedSchema) {
updateJson(tree, join(options.projectRoot, 'package.json'), (json) => {
export function updateDependencies(tree: Tree, options?: NormalizedSchema) {
updateJson(tree, join('package.json'), (json) => {
if (!json.devDependencies) {
json.devDependencies = {};
}
Expand All @@ -28,8 +28,8 @@ export function updateDependencies(tree: Tree, options: NormalizedSchema) {
});
}

export function updateNxJson(tree: Tree, options: NormalizedSchema) {
updateJson(tree, join(tree.root, 'nx.json'), (json) => {
export function updateNxJson(tree: Tree, options?: NormalizedSchema) {
updateJson(tree, join('nx.json'), (json) => {
if (json.tasksRunnerOptions) {
if (!json.tasksRunnerOptions.default.options.cacheableOperations) {
json.tasksRunnerOptions.default.options.cacheableOperations = []
Expand Down

0 comments on commit f0cd459

Please sign in to comment.