Skip to content

Commit

Permalink
feat: add vite plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ZachJW34 authored Dec 12, 2021
1 parent 0ddae49 commit f1c2628
Show file tree
Hide file tree
Showing 50 changed files with 1,706 additions and 62 deletions.
9 changes: 4 additions & 5 deletions apps/nuxt-e2e/tests/nuxt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import {
} from '@nrwl/nx-plugin/testing';

describe('nuxt e2e', () => {
beforeAll(() => {
ensureNxProject('@nx-plus/nuxt', 'dist/libs/nuxt');
});

it('should generate app', async () => {
const appName = uniq('app');
ensureNxProject('@nx-plus/nuxt', 'dist/libs/nuxt');
await runNxCommandAsync(`generate @nx-plus/nuxt:app ${appName}`);

const lintResult = await runNxCommandAsync(`lint ${appName}`);
Expand Down Expand Up @@ -57,7 +60,6 @@ describe('nuxt e2e', () => {

it('should report lint error in index.vue', async () => {
const appName = uniq('app');
ensureNxProject('@nx-plus/nuxt', 'dist/libs/nuxt');
await runNxCommandAsync(`generate @nx-plus/nuxt:app ${appName}`);

updateFile(
Expand All @@ -73,7 +75,6 @@ describe('nuxt e2e', () => {

it('should generate static app', async () => {
const appName = uniq('app');
ensureNxProject('@nx-plus/nuxt', 'dist/libs/nuxt');
await runNxCommandAsync(`generate @nx-plus/nuxt:app ${appName}`);

await runNxCommandAsync(`static ${appName}`);
Expand All @@ -92,7 +93,6 @@ describe('nuxt e2e', () => {
describe('--directory subdir', () => {
it('should generate app', async () => {
const appName = uniq('app');
ensureNxProject('@nx-plus/nuxt', 'dist/libs/nuxt');
await runNxCommandAsync(
`generate @nx-plus/nuxt:app ${appName} --directory subdir`
);
Expand Down Expand Up @@ -123,7 +123,6 @@ describe('nuxt e2e', () => {

it('should generate static app', async () => {
const appName = uniq('app');
ensureNxProject('@nx-plus/nuxt', 'dist/libs/nuxt');
await runNxCommandAsync(
`generate @nx-plus/nuxt:app ${appName} --directory subdir`
);
Expand Down
14 changes: 14 additions & 0 deletions apps/vite-e2e/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
displayName: 'vite-e2e',
preset: '../../jest.preset.js',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
},
},
transform: {
'^.+\\.[tj]s$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/apps/vite-e2e',
};
58 changes: 58 additions & 0 deletions apps/vite-e2e/tests/vite.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { tags } from '@angular-devkit/core';
import {
checkFilesExist,
ensureNxProject,
runNxCommandAsync,
uniq,
updateFile,
} from '@nrwl/nx-plugin/testing';
import { join } from 'path';

describe('vite e2e', () => {
it('should create vite app', async () => {
const appName = uniq('vite');
ensureNxProject('@nx-plus/vite', 'dist/libs/vite');
await runNxCommandAsync(`generate @nx-plus/vite:app ${appName}`);

const lintResult = await runNxCommandAsync(`lint ${appName}`);
expect(lintResult.stdout).toContain('All files pass linting.');

const testResult = await runNxCommandAsync(`test ${appName}`);
expect(testResult.stderr).toContain(tags.stripIndent`
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
`);

disableHashing(appName);
const buildResult = await runNxCommandAsync(`build ${appName}`);
checkFilesExist(
`dist/apps/${appName}/index.html`,
`dist/apps/${appName}/assets/index.css`,
`dist/apps/${appName}/assets/index.js`,
`dist/apps/${appName}/assets/vendor.js`
);
// Cannot disable hashing for assets
// see: https://github.com/vitejs/vite/issues/2944
expect(buildResult.stdout).toContain(`dist/apps/${appName}/assets/logo`);

const e2eResult = await runNxCommandAsync(`e2e ${appName}-e2e --headless`);
expect(e2eResult.stdout).toContain('All specs passed!');
}, 100000);
});

function disableHashing(app: string, directory: string = '') {
updateFile(join('apps', app, directory, 'vite.config.ts'), (content) =>
content.replace(
'emptyOutDir: true,',
`emptyOutDir: true,
rollupOptions: {
output: {
entryFileNames: \`assets/[name].js\`,
chunkFileNames: \`assets/[name].js\`,
assetFileNames: \`assets/[name].[ext]\`
}
}`
)
);
}
10 changes: 10 additions & 0 deletions apps/vite-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.spec.json"
}
]
}
9 changes: 9 additions & 0 deletions apps/vite-e2e/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["**/*.spec.ts", "**/*.d.ts"]
}
22 changes: 9 additions & 13 deletions apps/vue-e2e/tests/vue-2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import {
} from '@nrwl/nx-plugin/testing';
import { runNxProdCommandAsync, testGeneratedApp } from './utils';

describe('vue 2 e2e', () => {
describe.skip('vue 2 e2e', () => {
describe('app', () => {
beforeAll(() => {
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
});

it('should generate app', async () => {
const appName = uniq('app');
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
await runNxCommandAsync(`generate @nx-plus/vue:app ${appName}`);

await testGeneratedApp(appName, {
Expand All @@ -27,7 +30,6 @@ describe('vue 2 e2e', () => {
describe('--routing', () => {
it('should generate app with routing', async () => {
const appName = uniq('app');
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
await runNxCommandAsync(
`generate @nx-plus/vue:app ${appName} --routing`
);
Expand All @@ -52,7 +54,6 @@ describe('vue 2 e2e', () => {
describe('--style', () => {
it('should generate app with scss', async () => {
const appName = uniq('app');
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
await runNxCommandAsync(
`generate @nx-plus/vue:app ${appName} --style scss`
);
Expand All @@ -68,7 +69,6 @@ describe('vue 2 e2e', () => {

it('should generate app with stylus', async () => {
const appName = uniq('app');
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
await runNxCommandAsync(
`generate @nx-plus/vue:app ${appName} --style stylus`
);
Expand All @@ -84,7 +84,6 @@ describe('vue 2 e2e', () => {

it('should generate app with less', async () => {
const appName = uniq('app');
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
await runNxCommandAsync(
`generate @nx-plus/vue:app ${appName} --style less`
);
Expand All @@ -102,7 +101,6 @@ describe('vue 2 e2e', () => {
describe('vuex', () => {
it('should generate app and add vuex', async () => {
const appName = uniq('app');
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
await runNxCommandAsync(`generate @nx-plus/vue:app ${appName}`);
await runNxCommandAsync(`generate @nx-plus/vue:vuex ${appName}`);

Expand All @@ -118,7 +116,6 @@ describe('vue 2 e2e', () => {

it('should generate app with routing and add vuex', async () => {
const appName = uniq('app');
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
await runNxCommandAsync(`generate @nx-plus/vue:app ${appName} --routing`);
await runNxCommandAsync(`generate @nx-plus/vue:vuex ${appName}`);

Expand All @@ -140,7 +137,6 @@ describe('vue 2 e2e', () => {

it('should report lint error in App.vue', async () => {
const appName = uniq('app');
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
await runNxCommandAsync(`generate @nx-plus/vue:app ${appName}`);

updateFile(
Expand All @@ -157,7 +153,6 @@ describe('vue 2 e2e', () => {
describe('--directory subdir', () => {
it('should generate app', async () => {
const appName = uniq('app');
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
await runNxCommandAsync(
`generate @nx-plus/vue:app ${appName} --directory subdir`
);
Expand All @@ -177,9 +172,12 @@ describe('vue 2 e2e', () => {
});

describe('library', () => {
beforeAll(() => {
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
});

it('should generate lib', async () => {
const lib = uniq('lib');
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
await runNxCommandAsync(`generate @nx-plus/vue:lib ${lib}`);

const lintResult = await runNxCommandAsync(`lint ${lib}`);
Expand All @@ -195,7 +193,6 @@ describe('vue 2 e2e', () => {

it('should generate publishable lib', async () => {
const lib = uniq('lib');
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
await runNxCommandAsync(`generate @nx-plus/vue:lib ${lib} --publishable`);

let buildResult = await runNxProdCommandAsync(`build ${lib}`);
Expand Down Expand Up @@ -248,7 +245,6 @@ describe('vue 2 e2e', () => {
describe('--directory subdir', () => {
it('should generate publishable lib', async () => {
const lib = uniq('lib');
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
await runNxCommandAsync(
`generate @nx-plus/vue:lib ${lib} --directory subdir --publishable`
);
Expand Down
77 changes: 35 additions & 42 deletions apps/vue-e2e/tests/vue-3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import { runNxProdCommandAsync, testGeneratedApp } from './utils';

describe('vue 3 e2e', () => {
describe('app', () => {
beforeAll(() => {
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
});

it('should generate app', async () => {
const appName = uniq('app');
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
await runNxCommandAsync(
`generate @nx-plus/vue:app ${appName} --vueVersion 3`
);
Expand All @@ -29,7 +32,6 @@ describe('vue 3 e2e', () => {
describe('--routing', () => {
it('should generate app with routing', async () => {
const appName = uniq('app');
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
await runNxCommandAsync(
`generate @nx-plus/vue:app ${appName} --vueVersion 3 --routing`
);
Expand All @@ -54,7 +56,6 @@ describe('vue 3 e2e', () => {
describe('vuex', () => {
it('should generate app and add vuex', async () => {
const appName = uniq('app');
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
await runNxCommandAsync(
`generate @nx-plus/vue:app ${appName} --vueVersion 3`
);
Expand All @@ -72,7 +73,6 @@ describe('vue 3 e2e', () => {

it('should generate app with routing and add vuex', async () => {
const appName = uniq('app');
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
await runNxCommandAsync(
`generate @nx-plus/vue:app ${appName} --vueVersion 3 --routing`
);
Expand All @@ -96,7 +96,6 @@ describe('vue 3 e2e', () => {

it('should report lint error in App.vue', async () => {
const appName = uniq('app');
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
await runNxCommandAsync(
`generate @nx-plus/vue:app ${appName} --vueVersion 3`
);
Expand All @@ -111,12 +110,30 @@ describe('vue 3 e2e', () => {
});
expect(result.stderr).toContain('Lint errors found in the listed files.');
}, 300000);

it('should generate component', async () => {
const appName = uniq('app');
await runNxCommandAsync(
`generate @nx-plus/vue:app ${appName} --vueVersion 3`
);

await runNxCommandAsync(
`generate @nx-plus/vue:component my-component --project ${appName}`
);

expect(() =>
checkFilesExist(`apps/${appName}/src/MyComponent.vue`)
).not.toThrow();
}, 300000);
});

describe('library', () => {
beforeAll(() => {
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
});

it('should generate lib', async () => {
const lib = uniq('lib');
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
await runNxCommandAsync(
`generate @nx-plus/vue:lib ${lib} --vueVersion 3`
);
Expand All @@ -134,7 +151,6 @@ describe('vue 3 e2e', () => {

it('should generate publishable lib', async () => {
const lib = uniq('lib');
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
await runNxCommandAsync(
`generate @nx-plus/vue:lib ${lib} --vueVersion 3 --publishable`
);
Expand Down Expand Up @@ -185,43 +201,20 @@ describe('vue 3 e2e', () => {
)
).toThrow();
}, 300000);
});

describe('component', () => {
describe('inside an app', () => {
it('should generate component', async () => {
const appName = uniq('app');
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
await runNxCommandAsync(
`generate @nx-plus/vue:app ${appName} --vueVersion 3`
);

await runNxCommandAsync(
`generate @nx-plus/vue:component my-component --project ${appName}`
);

expect(() =>
checkFilesExist(`apps/${appName}/src/MyComponent.vue`)
).not.toThrow();
}, 300000);
});

describe('inside a library', () => {
it('should generate component', async () => {
const libName = uniq('lib');
ensureNxProject('@nx-plus/vue', 'dist/libs/vue');
await runNxCommandAsync(
`generate @nx-plus/vue:lib ${libName} --vueVersion 3`
);
it('should generate component', async () => {
const libName = uniq('lib');
await runNxCommandAsync(
`generate @nx-plus/vue:lib ${libName} --vueVersion 3`
);

await runNxCommandAsync(
`generate @nx-plus/vue:component my-component --project ${libName}`
);
await runNxCommandAsync(
`generate @nx-plus/vue:component my-component --project ${libName}`
);

expect(() =>
checkFilesExist(`libs/${libName}/src/lib/MyComponent.vue`)
).not.toThrow();
}, 300000);
});
expect(() =>
checkFilesExist(`libs/${libName}/src/lib/MyComponent.vue`)
).not.toThrow();
}, 300000);
});
});
3 changes: 3 additions & 0 deletions libs/vite/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": [["@nrwl/web/babel", { "useBuiltIns": "usage" }]]
}
Loading

0 comments on commit f1c2628

Please sign in to comment.