Skip to content

Commit

Permalink
fix: adjustments for nx 18 and update e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
sampullman committed May 13, 2024
1 parent 01233ce commit 588c46d
Show file tree
Hide file tree
Showing 17 changed files with 455 additions and 359 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ TODO -- automate changelog generation
- Update packages
- Update to Nx 18.3.4
- Make Cypress optional peer dependency
- BREAKING - may need to add project path to vitest executors in project.json. For example, `"config": "apps/myproject/vite.config.ts"`
- BREAKING - postcss config may need to be renamed from `postcss.config.js` to `postcss.config.mjs`

### v0.27.0 - 240117

Expand Down
142 changes: 77 additions & 65 deletions e2e/vue3-vite-e2e/tests/library.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getPackageManagerCommand } from '@nx/devkit';
import {
checkFilesExist,
cleanup,
Expand All @@ -16,24 +17,24 @@ jest.setTimeout(60000);
describe('library e2e', () => {
let proj: string;

afterAll(() => {
cleanup(proj);
});

describe('basic library check', () => {
beforeAll(() => {
proj = uniq('vue3-vite');
ensureNxProject('nx-vue3-vite', 'dist/packages/vue3-vite', proj);
});

afterAll(() => {
cleanup(proj);
});

it('should create library and build', async () => {
// Create library
const library = uniq('library');
await runNxCommandAsync(proj, `generate nx-vue3-vite:library ${library}`);

// Check files exist
checkFilesExist(proj, [
`libs/${library}/postcss.config.js`,
`libs/${library}/postcss.config.mjs`,
`libs/${library}/project.json`,
`libs/${library}/vite.config.ts`,
`libs/${library}/src/index.ts`,
Expand Down Expand Up @@ -100,7 +101,7 @@ describe('library e2e', () => {

// Lint
const lintResult = await runNxCommandAsync(proj, `lint ${library}`);
expect(lintResult.stdout).toContain('All files pass linting.');
expect(lintResult.stdout).toContain('All files pass linting');
});

it('should add path to `tsconfig.base.json`', async () => {
Expand All @@ -120,56 +121,67 @@ describe('library e2e', () => {
});
});

it('should not overwrite `dependencies` in `package.json`', async () => {
// Reset project to verify correct dependencies are installed
proj = uniq('vue3-vite');
ensureNxProject('nx-vue3-vite', 'dist/packages/vue3-vite', proj);

// Install Vue 2
const packageName = 'vue';
const oldVersion = '^2.7.16';
await runCommandAsync(
proj,
`npm install ${packageName}@${oldVersion} --save`,
);

// Verify `dependencies` after install
let packageJson = readJson(proj, 'package.json');
expect(packageJson.dependencies[packageName]).toEqual(oldVersion);

// Create library
const library = uniq('library-dep');
await runNxCommandAsync(proj, `generate nx-vue3-vite:library ${library}`);

// Verify `dependencies` after running the generator
packageJson = readJson(proj, 'package.json');
expect(packageJson.dependencies[packageName]).toEqual(oldVersion);
});
describe('update configuration', () => {
beforeEach(() => {
proj = uniq('vue3-vite');
ensureNxProject('nx-vue3-vite', 'dist/packages/vue3-vite', proj);
});

afterEach(() => {
cleanup(proj);
});

it('should not overwrite `dependencies` in `package.json`', async () => {
const pmc = getPackageManagerCommand();

// Install Vue 2
const packageName = 'vue';
const oldVersion = '^2.7.16';
await runCommandAsync(
proj,
`${pmc.install} ${packageName}@${oldVersion} --save`,
);

// Verify `dependencies` after install
let packageJson = readJson(proj, 'package.json');
expect(packageJson.dependencies[packageName]).toEqual(oldVersion);

// Create library
const library = uniq('library-dep');
await runNxCommandAsync(proj, `generate nx-vue3-vite:library ${library}`);

// Verify `dependencies` after running the generator
packageJson = readJson(proj, 'package.json');
expect(packageJson.dependencies[packageName]).toEqual(oldVersion);
});

it('should not overwrite `devDependencies` in `package.json`', async () => {
// Reset project to verify correct dependencies are installed
proj = uniq('vue3-vite');
ensureNxProject('nx-vue3-vite', 'dist/packages/vue3-vite', proj);

// Install Vite 3
const packageName = 'vite';
const oldVersion = '^3.2.10';
await runCommandAsync(
proj,
`npm install ${packageName}@${oldVersion} --save-dev`,
);

// Verify `dependencies` after install
let packageJson = readJson(proj, 'package.json');
expect(packageJson.devDependencies[packageName]).toEqual(oldVersion);

// Create library
const library = uniq('library-dev-dep');
await runNxCommandAsync(proj, `generate nx-vue3-vite:library ${library}`);

// Verify `devDepndencies` after running the generator
packageJson = readJson(proj, 'package.json');
expect(packageJson.devDependencies[packageName]).toEqual(oldVersion);
it('should not overwrite `devDependencies` in `package.json`', async () => {
const pmc = getPackageManagerCommand();

// Install Vite 3
const packageName = 'vite';
const oldVersion = '5.2.5';
await runCommandAsync(
proj,
`${pmc.install} -D ${packageName}@${oldVersion}`,
);

// Verify `dependencies` after install
let packageJson = readJson(proj, 'package.json');
expect(packageJson.devDependencies[packageName]).toEqual(
`^${oldVersion}`,
);

// Create library
const library = uniq('library-dev-dep');
await runNxCommandAsync(proj, `generate nx-vue3-vite:library ${library}`);

// Verify `devDepndencies` after running the generator
packageJson = readJson(proj, 'package.json');
expect(packageJson.devDependencies[packageName]).toEqual(
`^${oldVersion}`,
);
});
});

describe('--test', () => {
Expand All @@ -179,11 +191,11 @@ describe('library e2e', () => {
ensureNxProject('nx-vue3-vite', 'dist/packages/vue3-vite', proj);
});

it.only('lints and uses Vitest as testing framework by default', async () => {
// Reset project to verify correct dependencies are installed
proj = uniq('vue3-vite');
ensureNxProject('nx-vue3-vite', 'dist/packages/vue3-vite', proj);
afterAll(() => {
cleanup(proj);
});

it('lints and uses Vitest as testing framework by default', async () => {
// Create library
const library = uniq('lib-test');
await runNxCommandAsync(
Expand Down Expand Up @@ -211,7 +223,7 @@ describe('library e2e', () => {

// Lint
const lintResult = await runNxCommandAsync(proj, `lint ${library}`);
expect(lintResult.stdout).toContain('All files pass linting.');
expect(lintResult.stdout).toContain('All files pass linting');
});

it('runs tests with Vitest when `test` equals to "vitest"', async () => {
Expand All @@ -236,11 +248,11 @@ describe('library e2e', () => {
ensureNxProject('nx-vue3-vite', 'dist/packages/vue3-vite', proj);
});

it('lints and uses Jest as testing framework when `test` equals to "jest"', async () => {
// Reset project to verify correct dependencies are installed
proj = uniq('vue3-vite');
ensureNxProject('nx-vue3-vite', 'dist/packages/vue3-vite', proj);
afterAll(() => {
cleanup(proj);
});

it('lints and uses Jest as testing framework when `test` equals to "jest"', async () => {
// Create library
const library = uniq('lib-test');
await runNxCommandAsync(
Expand Down Expand Up @@ -268,7 +280,7 @@ describe('library e2e', () => {

// Lint
const lintResult = await runNxCommandAsync(proj, `lint ${library}`);
expect(lintResult.stdout).toContain('All files pass linting.');
expect(lintResult.stdout).toContain('All files pass linting');
});

it('runs tests with Jest when `test` equals to "jest"', async () => {
Expand Down
6 changes: 5 additions & 1 deletion e2e/vue3-vite-e2e/tests/utils/async-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,9 @@ export function runNxCommandAsync(
},
): Promise<{ stdout: string; stderr: string }> {
const pmc = getPackageManagerCommand();
return runCommandAsync(projectPath, `${pmc.exec} nx ${command}`, opts);
return runCommandAsync(
projectPath,
`NX_DAEMON=false ${pmc.exec} nx ${command}`,
opts,
);
}
Loading

0 comments on commit 588c46d

Please sign in to comment.