Skip to content

Commit

Permalink
fix(tests): fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ygj6 committed Jul 2, 2021
1 parent 5c13caa commit 83d9494
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
17 changes: 11 additions & 6 deletions tests/generate.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { genePackageJson } from '../src/generate/genePackageJson';
import path from 'path';
import fs from 'fs';
import { genIndexHtml } from '../src/generate/geneIndexHtml';
import { readSync } from '../src/utils/file';
import * as constants from '../src/constants/constants';
import { genePackageJson } from '../src/generate/genePackageJson';
import { geneIndexHtml } from '../src/generate/geneIndexHtml';
import { readSync } from '../src/utils/file';
import { Config } from '../src/config/config'

test('genePackageJson', () => {
const packageJsonPath = path.resolve('./tests/testdata/generate/package.json');
Expand All @@ -14,9 +15,13 @@ test('genePackageJson', () => {
expect(JSON.parse(packageJsonContent).devDependencies['@vitejs/plugin-vue']).toEqual(constants.VITE_PLUGIN_VUE_VERSION);
});

test('genIndexHtml', () => {
genIndexHtml('./tests/out');
test('geneIndexHtml', () => {
const config : Config = {
projectType: 'vue-cli'
}
geneIndexHtml(path.resolve('./tests/out'), config);
const filePath = path.resolve('./tests/out/index.html');
const content = readSync(filePath);
expect(content).toContain('src/main.js');
expect(content).toContain('<div id="app"></div>');

})
13 changes: 10 additions & 3 deletions tests/render.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import path from 'path';
import { geneViteConfig } from '../src/generate/geneViteConfig';
import fs from 'fs';
import { Config } from '../src/config/config'
import { geneViteConfig } from '../src/generate/geneViteConfig';
import { serializeObject } from '../src/generate/render';

test('geneViteConfig from non exist file', async () => {
const outputFilePath = path.resolve('tests/out/vite.config.js');
const vueConfigPath = path.resolve('tests/nosuchfile');
await geneViteConfig(vueConfigPath, path.resolve('tests/out'), 'vue-cli');
const config : Config = {
projectType: 'vue-cli'
}
await geneViteConfig(vueConfigPath, path.resolve('tests/out'), config);
const result = fs.readFileSync(outputFilePath, 'utf8');
expect(result).toContain('plugins');
});

test('geneViteConfig from vue.config.js', async () => {
const outputFilePath = path.resolve('tests/out/vite.config.js');
const vueConfigPath = path.resolve('tests/testdata');
await geneViteConfig(vueConfigPath, path.resolve('tests/out'), 'vue-cli');
const config : Config = {
projectType: 'vue-cli',
}
await geneViteConfig(vueConfigPath, path.resolve('tests/out'), config);
const result = fs.readFileSync(outputFilePath, 'utf8');
expect(result).toContain('@components');
});
Expand Down

0 comments on commit 83d9494

Please sign in to comment.