Skip to content

Commit

Permalink
fix(remix): do not rename root jest.preset.js (#21703)
Browse files Browse the repository at this point in the history
(cherry picked from commit ec00acd)
  • Loading branch information
Coly010 authored and FrozenPandaz committed Feb 9, 2024
1 parent 5b50704 commit ae090ef
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 135 deletions.
288 changes: 161 additions & 127 deletions e2e/remix/tests/nx-remix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,164 +11,198 @@ import {
listFiles,
} from '@nx/e2e/utils';

describe('remix e2e', () => {
let proj: string;
describe('Remix E2E Tests', () => {
describe('--integrated', () => {
let proj: string;

beforeAll(() => {
proj = newProject({ packages: ['@nx/remix'] });
});

afterAll(() => {
killPorts();
cleanupProject();
});
beforeAll(() => {
proj = newProject({ packages: ['@nx/remix', '@nx/react'] });
});

it('should create a standalone remix app', async () => {
const appName = uniq('remix');
runCLI(`generate @nx/remix:preset --name ${appName} --verbose`);
afterAll(() => {
killPorts();
cleanupProject();
});

// Can import using ~ alias like a normal Remix setup.
updateFile(`app/foo.ts`, `export const foo = 'foo';`);
updateFile(
`app/routes/index.tsx`,
`
import { foo } from '~/foo';
export default function Index() {
return (
<h1>{foo}</h1>
);
}
`
);
it('should create app', async () => {
const plugin = uniq('remix');
runCLI(`generate @nx/remix:app ${plugin}`);

const result = runCLI(`build ${appName}`);
expect(result).toContain('Successfully ran target build');
}, 120_000);
const buildResult = runCLI(`build ${plugin}`);
expect(buildResult).toContain('Successfully ran target build');

it('should create app', async () => {
const plugin = uniq('remix');
runCLI(`generate @nx/remix:app ${plugin}`);
const testResult = runCLI(`test ${plugin}`);
expect(testResult).toContain('Successfully ran target test');
}, 120000);

const buildResult = runCLI(`build ${plugin}`);
expect(buildResult).toContain('Successfully ran target build');
describe('--directory', () => {
it('should create src in the specified directory --projectNameAndRootFormat=derived', async () => {
const plugin = uniq('remix');
const appName = `sub-${plugin}`;
runCLI(
`generate @nx/remix:app ${plugin} --directory=sub --projectNameAndRootFormat=derived --rootProject=false --no-interactive`
);

const testResult = runCLI(`test ${plugin}`);
expect(testResult).toContain('Successfully ran target test');
}, 120000);
const result = runCLI(`build ${appName}`);
expect(result).toContain('Successfully ran target build');

describe('--directory', () => {
it('should create src in the specified directory --projectNameAndRootFormat=derived', async () => {
const plugin = uniq('remix');
const appName = `sub-${plugin}`;
runCLI(
`generate @nx/remix:app ${plugin} --directory=sub --projectNameAndRootFormat=derived --rootProject=false --no-interactive`
);
// TODO(colum): uncomment line below when fixed
checkFilesExist(`dist/apps/sub/${plugin}/build/index.js`);
}, 120000);

const result = runCLI(`build ${appName}`);
expect(result).toContain('Successfully ran target build');
it('should create src in the specified directory --projectNameAndRootFormat=as-provided', async () => {
const plugin = uniq('remix');
runCLI(
`generate @nx/remix:app ${plugin} --directory=subdir --projectNameAndRootFormat=as-provided --rootProject=false --no-interactive`
);

// TODO(colum): uncomment line below when fixed
// checkFilesExist(`dist/apps/sub/${plugin}/build/index.js`);
}, 120000);
const result = runCLI(`build ${plugin}`);
expect(result).toContain('Successfully ran target build');
checkFilesExist(`dist/subdir/build/index.js`);
}, 120000);
});

describe('--tags', () => {
it('should add tags to the project', async () => {
const plugin = uniq('remix');
runCLI(`generate @nx/remix:app ${plugin} --tags e2etag,e2ePackage`);
const project = readJson(`apps/${plugin}/project.json`);
expect(project.tags).toEqual(['e2etag', 'e2ePackage']);
}, 120000);
});

describe('--js', () => {
it('should create js app and build correctly', async () => {
const plugin = uniq('remix');
runCLI(`generate @nx/remix:app ${plugin} --js=true`);

const result = runCLI(`build ${plugin}`);
expect(result).toContain('Successfully ran target build');
}, 120000);
});

describe('--unitTestRunner', () => {
it('should generate a library with vitest and test correctly', async () => {
const plugin = uniq('remix');
runCLI(`generate @nx/remix:library ${plugin} --unitTestRunner=vitest`);

const result = runCLI(`test ${plugin}`);
expect(result).toContain(`Successfully ran target test`);
}, 120_000);

it('should generate a library with jest and test correctly', async () => {
const reactapp = uniq('react');
runCLI(
`generate @nx/react:application ${reactapp} --unitTestRunner=jest`
);
const plugin = uniq('remix');
runCLI(
`generate @nx/remix:application ${plugin} --unitTestRunner=jest`
);

it('should create src in the specified directory --projectNameAndRootFormat=as-provided', async () => {
const plugin = uniq('remix');
runCLI(
`generate @nx/remix:app ${plugin} --directory=subdir --projectNameAndRootFormat=as-provided --rootProject=false --no-interactive`
);
const result = runCLI(`test ${plugin}`);
expect(result).toContain(`Successfully ran target test`);

const result = runCLI(`build ${plugin}`);
expect(result).toContain('Successfully ran target build');
checkFilesExist(`dist/subdir/build/index.js`);
}, 120000);
});
const reactResult = runCLI(`test ${reactapp}`);
expect(result).toContain(`Successfully ran target test`);
}, 120_000);
});

describe('--tags', () => {
it('should add tags to the project', async () => {
describe('error checking', () => {
const plugin = uniq('remix');
runCLI(`generate @nx/remix:app ${plugin} --tags e2etag,e2ePackage`);
const project = readJson(`${plugin}/project.json`);
expect(project.tags).toEqual(['e2etag', 'e2ePackage']);
}, 120000);
});

describe('--js', () => {
it('should create js app and build correctly', async () => {
const plugin = uniq('remix');
runCLI(`generate @nx/remix:app ${plugin} --js=true`);
beforeAll(async () => {
runCLI(`generate @nx/remix:app ${plugin} --tags e2etag,e2ePackage`);
}, 120000);

const result = runCLI(`build ${plugin}`);
expect(result).toContain('Successfully ran target build');
}, 120000);
});
it('should check for un-escaped dollar signs in routes', async () => {
await expect(async () =>
runCLI(
`generate @nx/remix:route --project ${plugin} --path my.route.$withParams.tsx`
)
).rejects.toThrow();

describe('--unitTestRunner', () => {
it('should generate a library with vitest and test correctly', async () => {
const plugin = uniq('remix');
runCLI(`generate @nx/remix:library ${plugin} --unitTestRunner=vitest`);
runCLI(
`generate @nx/remix:route --project ${plugin} --path my.route.\\$withParams.tsx`
);

const result = runCLI(`test ${plugin}`);
expect(result).toContain(`Successfully ran target test`);
}, 120_000);
});
expect(() =>
checkFilesExist(`apps/${plugin}/app/routes/my.route.$withParams.tsx`)
).not.toThrow();
}, 120000);

describe('error checking', () => {
const plugin = uniq('remix');
it('should pass un-escaped dollar signs in routes with skipChecks flag', async () => {
await runCommandAsync(
`someWeirdUseCase=route-segment && yarn nx generate @nx/remix:route --project ${plugin} --path my.route.$someWeirdUseCase.tsx --force`
);

beforeAll(async () => {
runCLI(`generate @nx/remix:app ${plugin} --tags e2etag,e2ePackage`);
}, 120000);
expect(() =>
checkFilesExist(
`apps/${plugin}/app/routes/my.route.route-segment.tsx`
)
).not.toThrow();
}, 120000);

it('should check for un-escaped dollar signs in resource routes', async () => {
await expect(async () =>
runCLI(
`generate @nx/remix:resource-route --project ${plugin} --path my.route.$withParams.ts`
)
).rejects.toThrow();

it('should check for un-escaped dollar signs in routes', async () => {
await expect(async () =>
runCLI(
`generate @nx/remix:route --project ${plugin} --path my.route.$withParams.tsx`
)
).rejects.toThrow();
`generate @nx/remix:resource-route --project ${plugin} --path my.route.\\$withParams.ts`
);

runCLI(
`generate @nx/remix:route --project ${plugin} --path my.route.\\$withParams.tsx`
);
expect(() =>
checkFilesExist(`apps/${plugin}/app/routes/my.route.$withParams.ts`)
).not.toThrow();
}, 120000);

expect(() =>
checkFilesExist(`${plugin}/app/routes/my.route.$withParams.tsx`)
).not.toThrow();
}, 120000);
it('should pass un-escaped dollar signs in resource routes with skipChecks flag', async () => {
await runCommandAsync(
`someWeirdUseCase=route-segment && yarn nx generate @nx/remix:resource-route --project ${plugin} --path my.route.$someWeirdUseCase.ts --force`
);

it('should pass un-escaped dollar signs in routes with skipChecks flag', async () => {
await runCommandAsync(
`someWeirdUseCase=route-segment && yarn nx generate @nx/remix:route --project ${plugin} --path my.route.$someWeirdUseCase.tsx --force`
);
expect(() =>
checkFilesExist(`apps/${plugin}/app/routes/my.route.route-segment.ts`)
).not.toThrow();
}, 120000);
});
});

expect(() =>
checkFilesExist(`${plugin}/app/routes/my.route.route-segment.tsx`)
).not.toThrow();
}, 120000);
describe('--standalone', () => {
let proj: string;

it('should check for un-escaped dollar signs in resource routes', async () => {
await expect(async () =>
runCLI(
`generate @nx/remix:resource-route --project ${plugin} --path my.route.$withParams.ts`
)
).rejects.toThrow();
beforeAll(() => {
proj = newProject({ packages: ['@nx/remix'] });
});

runCLI(
`generate @nx/remix:resource-route --project ${plugin} --path my.route.\\$withParams.ts`
);
afterAll(() => {
killPorts();
cleanupProject();
});

expect(() =>
checkFilesExist(`${plugin}/app/routes/my.route.$withParams.ts`)
).not.toThrow();
}, 120000);
it('should create a standalone remix app', async () => {
const appName = uniq('remix');
runCLI(`generate @nx/remix:preset --name ${appName} --verbose`);

it('should pass un-escaped dollar signs in resource routes with skipChecks flag', async () => {
await runCommandAsync(
`someWeirdUseCase=route-segment && yarn nx generate @nx/remix:resource-route --project ${plugin} --path my.route.$someWeirdUseCase.ts --force`
// Can import using ~ alias like a normal Remix setup.
updateFile(`app/foo.ts`, `export const foo = 'foo';`);
updateFile(
`app/routes/index.tsx`,
`
import { foo } from '~/foo';
export default function Index() {
return (
<h1>{foo}</h1>
);
}
`
);

expect(() =>
checkFilesExist(`${plugin}/app/routes/my.route.route-segment.ts`)
).not.toThrow();
}, 120000);
const result = runCLI(`build ${appName}`);
expect(result).toContain('Successfully ran target build');
}, 120_000);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,8 @@ export default {
exports[`Remix Application Integrated Repo --projectNameAndRootFormat=as-provided --unitTestRunner should generate the correct files for testing using jest 2`] = `
"/* eslint-disable */
export default {
setupFilesAfterEnv: ['<rootDir>/test-setup.ts'],
displayName: 'test',
preset: '../jest.preset.cjs',
preset: '../jest.preset.js',
transform: {
'^.+\\\\.[tj]sx?$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
Expand Down Expand Up @@ -801,9 +800,8 @@ export default {
exports[`Remix Application Integrated Repo --projectNameAndRootFormat=derived --unitTestRunner should generate the correct files for testing using jest 2`] = `
"/* eslint-disable */
export default {
setupFilesAfterEnv: ['<rootDir>/test-setup.ts'],
displayName: 'test',
preset: '../../jest.preset.cjs',
preset: '../../jest.preset.js',
transform: {
'^.+\\\\.[tj]sx?$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ export async function remixApplicationGeneratorInternal(
const pkgInstallTask = updateUnitTestConfig(
tree,
options.projectRoot,
options.unitTestRunner
options.unitTestRunner,
options.rootProject
);
tasks.push(pkgInstallTask);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
export function updateUnitTestConfig(
tree: Tree,
pathToRoot: string,
unitTestRunner: 'vitest' | 'jest'
unitTestRunner: 'vitest' | 'jest',
rootProject: boolean
) {
const pathToTestSetup = joinPathFragments(pathToRoot, `test-setup.ts`);
tree.write(
Expand All @@ -45,9 +46,9 @@ export function updateUnitTestConfig(
'./tests/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'
);
updateVitestTestSetup(tree, pathToViteConfig, 'test-setup.ts');
} else if (unitTestRunner === 'jest') {
} else if (unitTestRunner === 'jest' && rootProject) {
const pathToJestConfig = joinPathFragments(pathToRoot, 'jest.config.ts');
tree.rename('jest.preset.js', 'jest.preset.cjs');
tree.write('jest.preset.cjs', tree.read('jest.preset.js', 'utf-8'));
updateJestTestSetup(tree, pathToJestConfig, `<rootDir>/test-setup.ts`);
tree.write(
pathToJestConfig,
Expand Down

0 comments on commit ae090ef

Please sign in to comment.