Nicholas Cunningham 32f60f11f4
fix(vite): update nx.json for vitest (#13606)
Co-authored-by: Nicholas Cunningham <ndcunningham>
2022-12-02 17:35:01 -05:00

64 lines
1.8 KiB
TypeScript

import {
addDependenciesToPackageJson,
NxJsonConfiguration,
readJson,
Tree,
updateJson,
} from '@nrwl/devkit';
import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing';
import { nxVersion } from '../../utils/versions';
import { initGenerator } from './init';
describe('@nrwl/vite:init', () => {
let tree: Tree;
beforeEach(() => {
tree = createTreeWithEmptyV1Workspace();
});
describe('dependencies for package.json', () => {
it('should add vite packages and react-related dependencies for vite', async () => {
const existing = 'existing';
const existingVersion = '1.0.0';
addDependenciesToPackageJson(
tree,
{ '@nrwl/vite': nxVersion, [existing]: existingVersion },
{ [existing]: existingVersion }
);
await initGenerator(tree, {
uiFramework: 'react',
});
const packageJson = readJson(tree, 'package.json');
expect(packageJson).toMatchSnapshot();
});
});
describe('vitest targets', () => {
it('should add target defaults for test', async () => {
updateJson<NxJsonConfiguration>(tree, 'nx.json', (json) => {
json.namedInputs ??= {};
json.namedInputs.production = ['default'];
return json;
});
initGenerator(tree, { uiFramework: 'react' });
const productionNamedInputs = readJson(tree, 'nx.json').namedInputs
.production;
const testDefaults = readJson(tree, 'nx.json').targetDefaults.test;
expect(productionNamedInputs).toContain(
'!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)'
);
expect(productionNamedInputs).toContain(
'!{projectRoot}/tsconfig.spec.json'
);
expect(testDefaults).toEqual({
inputs: ['default', '^production'],
});
});
});
});