Skip to content

Commit

Permalink
cleanup(misc): add more test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez committed Nov 29, 2024
1 parent 9cf59b1 commit 88db393
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/expo/src/generators/component/component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ describe('component', () => {
expect(appTree.exists('my-lib/src/lib/hello/hello.spec.tsx')).toBeTruthy();
});

it('should handle path with file extension', async () => {
await expoComponentGenerator(appTree, {
...defaultSchema,
path: 'my-lib/src/lib/hello/hello.tsx',
});

expect(appTree.exists('my-lib/src/lib/hello/hello.tsx')).toBeTruthy();
expect(appTree.exists('my-lib/src/lib/hello/hello.spec.tsx')).toBeTruthy();
});

it('should generate files for an app', async () => {
await expoComponentGenerator(appTree, {
...defaultSchema,
Expand Down
13 changes: 13 additions & 0 deletions packages/next/src/generators/component/component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ describe('component', () => {
).toBeTruthy();
});

it('should handle path with file extension', async () => {
await componentGenerator(tree, {
path: `${appName}/components/hello/hello.tsx`,
style: 'css',
});

expect(tree.exists('my-app/components/hello/hello.tsx')).toBeTruthy();
expect(tree.exists('my-app/components/hello/hello.spec.tsx')).toBeTruthy();
expect(
tree.exists('my-app/components/hello/hello.module.css')
).toBeTruthy();
});

it('should generate component in default directory for library', async () => {
await componentGenerator(tree, {
name: 'hello',
Expand Down
22 changes: 22 additions & 0 deletions packages/plugin/src/generators/executor/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,28 @@ describe('NxPlugin Executor Generator', () => {
).toBeTruthy();
});

it('should handle path with file extension', async () => {
await executorGenerator(tree, {
name: 'my-executor',
path: 'my-plugin/src/executors/my-executor/executor.ts',
unitTestRunner: 'jest',
includeHasher: false,
});

expect(
tree.exists('my-plugin/src/executors/my-executor/schema.d.ts')
).toBeTruthy();
expect(
tree.exists('my-plugin/src/executors/my-executor/schema.json')
).toBeTruthy();
expect(
tree.exists('my-plugin/src/executors/my-executor/executor.ts')
).toBeTruthy();
expect(
tree.exists('my-plugin/src/executors/my-executor/executor.spec.ts')
).toBeTruthy();
});

it('should generate files relative to the cwd', async () => {
setCwd('my-plugin/src/executors/my-executor');
await executorGenerator(tree, {
Expand Down
21 changes: 21 additions & 0 deletions packages/plugin/src/generators/generator/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@ describe('NxPlugin Generator Generator', () => {
).toBeTruthy();
});

it('should handle path with file extension', async () => {
await generatorGenerator(tree, {
name: 'my-generator',
path: 'my-plugin/src/generators/my-generator/generator.ts',
unitTestRunner: 'jest',
});

expect(
tree.exists('my-plugin/src/generators/my-generator/schema.d.ts')
).toBeTruthy();
expect(
tree.exists('my-plugin/src/generators/my-generator/schema.json')
).toBeTruthy();
expect(
tree.exists('my-plugin/src/generators/my-generator/generator.ts')
).toBeTruthy();
expect(
tree.exists('my-plugin/src/generators/my-generator/generator.spec.ts')
).toBeTruthy();
});

it('should generate files relative to cwd', async () => {
setCwd('my-plugin/src/nx-integrations/generators/my-generator');
await generatorGenerator(tree, {
Expand Down
28 changes: 28 additions & 0 deletions packages/plugin/src/generators/migration/migration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,34 @@ describe('NxPlugin migration generator', () => {
);
});

it('should handle path with file extension', async () => {
await migrationGenerator(tree, {
name: 'my-migration',
path: 'packages/my-plugin/migrations/1.0.0/my-migration.ts',
packageVersion: '1.0.0',
});

const migrationsJson = readJson(tree, 'packages/my-plugin/migrations.json');
const packageJson = readJson(tree, 'packages/my-plugin/package.json');

expect(
tree.exists('packages/my-plugin/migrations/1.0.0/my-migration.ts')
).toBeTruthy();

expect(migrationsJson.generators['my-migration'].version).toEqual('1.0.0');
expect(migrationsJson.generators['my-migration'].description).toEqual(
'Migration for v1.0.0'
);
expect(migrationsJson.generators['my-migration'].implementation).toEqual(
'./migrations/1.0.0/my-migration'
);
expect(migrationsJson.packageJsonUpdates).toBeFalsy();

expect(packageJson['nx-migrations'].migrations).toEqual(
'./migrations.json'
);
});

it('should generate files with default name', async () => {
await migrationGenerator(tree, {
description: 'my-migration description',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ describe('component', () => {
expect(appTree.exists('my-lib/src/lib/hello/hello.spec.tsx')).toBeTruthy();
});

it('should handle path with file extension', async () => {
await reactNativeComponentGenerator(appTree, {
path: `${projectName}/src/lib/hello/hello.tsx`,
});

expect(appTree.exists('my-lib/src/lib/hello/hello.tsx')).toBeTruthy();
expect(appTree.exists('my-lib/src/lib/hello/hello.spec.tsx')).toBeTruthy();
});

it('should generate files for an app', async () => {
await reactNativeComponentGenerator(appTree, {
name: 'hello',
Expand Down
20 changes: 20 additions & 0 deletions packages/react/src/generators/component/component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ describe('component', () => {
);
});

it('should handle path with file extension', async () => {
await componentGenerator(appTree, {
name: 'hello',
style: 'css',
path: `${projectName}/src/lib/hello/hello.tsx`,
});

expect(appTree.exists('my-lib/src/lib/hello/hello.tsx')).toBeTruthy();
expect(appTree.exists('my-lib/src/lib/hello/hello.spec.tsx')).toBeTruthy();
expect(
appTree.exists('my-lib/src/lib/hello/hello.module.css')
).toBeTruthy();
expect(appTree.read('my-lib/src/lib/hello/hello.tsx').toString()).toMatch(
/import styles from '.\/hello.module.css'/
);
expect(appTree.read('my-lib/src/lib/hello/hello.tsx').toString()).toMatch(
/<div className={styles\['container']}>/
);
});

it('should generate files with global CSS', async () => {
await componentGenerator(appTree, {
name: 'hello',
Expand Down
11 changes: 11 additions & 0 deletions packages/react/src/generators/hook/hook.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ describe('hook', () => {
).toBeTruthy();
});

it('should handle path with file extension', async () => {
await hookGenerator(appTree, {
path: `${projectName}/src/lib/use-form/use-form.ts`,
});

expect(appTree.exists('my-lib/src/lib/use-form/use-form.ts')).toBeTruthy();
expect(
appTree.exists('my-lib/src/lib/use-form/use-form.spec.tsx')
).toBeTruthy();
});

it('should generate files for an app', async () => {
await hookGenerator(appTree, {
name: 'use-form',
Expand Down
33 changes: 33 additions & 0 deletions packages/vue/src/generators/component/component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,39 @@ describe('component', () => {
`);
});

it('should handle path with file extension', async () => {
await componentGenerator(appTree, {
path: `${libName}/src/lib/hello/hello.vue`,
});

expect(appTree.read(`${libName}/src/lib/hello/hello.vue`, 'utf-8'))
.toMatchInlineSnapshot(`
"<script setup lang="ts">
// defineProps<{}>()
</script>
<template>
<p>Welcome to Hello!</p>
</template>
<style scoped></style>
"
`);
expect(appTree.read(`${libName}/src/lib/hello/hello.spec.ts`, 'utf-8'))
.toMatchInlineSnapshot(`
"import { mount } from '@vue/test-utils';
import Hello from './hello.vue';
describe('Hello', () => {
it('renders properly', () => {
const wrapper = mount(Hello, {});
expect(wrapper.text()).toContain('Welcome to Hello');
});
});
"
`);
});

it('should have correct component name based on directory', async () => {
await componentGenerator(appTree, {
path: `${libName}/src/foo/bar/hello-world/hello-world`,
Expand Down

0 comments on commit 88db393

Please sign in to comment.