Skip to content

Commit

Permalink
refactor superset-generator
Browse files Browse the repository at this point in the history
fix refactor genertor lint error
  • Loading branch information
zhaoyongjie committed Nov 25, 2021
1 parent e87fdc4 commit c539787
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 129 deletions.
3 changes: 2 additions & 1 deletion superset-frontend/packages/generator-superset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
],
"devDependencies": {
"yeoman-assert": "^3.1.0",
"yeoman-test": "^2.0.0"
"yeoman-test": "^6.2.0",
"fs-extra": "^10.0.0"
},
"engines": {
"npm": ">= 4.0.0"
Expand Down
49 changes: 14 additions & 35 deletions superset-frontend/packages/generator-superset/test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,22 @@
* under the License.
*/

const path = require('path');
const assert = require('yeoman-assert');
const helpers = require('yeoman-test');
const appModule = require('../generators/app');

describe('generator-superset:app', () => {
let dir;

beforeAll(() => {
dir = process.cwd();

return helpers.run(path.join(__dirname, '../generators/app')).withPrompts({
test('generator-superset:app:creates files', () =>
helpers
.run(appModule)
.withPrompts({
subgenerator: 'package',
name: 'my-package',
});
});

/*
* Change working directory back to original working directory
* after the test has completed.
* yeoman tests switch to tmp directory and write files there.
* Usually this is fine for solo package.
* However, for a monorepo like this one,
* it made jest confuses with current directory
* (being in tmp directory instead of superset-ui root)
* and interferes with other tests in sibling packages
* that are run after the yeoman tests.
*/
afterAll(() => {
process.chdir(dir);
});

it('creates files', () => {
assert.file([
'package.json',
'README.md',
'src/index.ts',
'test/index.test.ts',
]);
});
});
})
.then(function () {
assert.file([
'package.json',
'README.md',
'src/index.ts',
'test/index.test.ts',
]);
}));
73 changes: 26 additions & 47 deletions superset-frontend/packages/generator-superset/test/package.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,62 +20,41 @@
const path = require('path');
const assert = require('yeoman-assert');
const helpers = require('yeoman-test');

describe('generator-superset:package', () => {
let dir;

beforeAll(() => {
dir = process.cwd();
});

/*
* Change working directory back to original working directory
* after the test has completed.
* yeoman tests switch to tmp directory and write files there.
* Usually this is fine for solo package.
* However, for a monorepo like this one,
* it made jest confuses with current directory
* (being in tmp directory instead of superset-ui root)
* and interferes with other tests in sibling packages
* that are run after the yeoman tests.
*/
afterAll(() => {
process.chdir(dir);
});

describe('typescript', () => {
beforeAll(() =>
helpers
.run(path.join(__dirname, '../generators/package'))
.withPrompts({ name: 'my-package', language: 'typescript' })
.withOptions({ skipInstall: true }),
);

it('creates files', () => {
const fs = require('fs-extra');
const packageModule = require('../generators/package');

test('generator-superset:package:creates typescript files', () =>
helpers
.run(packageModule)
.inTmpDir(function (dir) {
// `dir` is the path to the new temporary directory
fs.copySync(path.join(__dirname, '../generators/package'), dir);
})
.withPrompts({ name: 'my-package', language: 'typescript' })
.withOptions({ skipInstall: true })
.then(function () {
assert.file([
'package.json',
'README.md',
'src/index.ts',
'test/index.test.ts',
]);
});
});

describe('javascript', () => {
beforeAll(() =>
helpers
.run(path.join(__dirname, '../generators/package'))
.withPrompts({ name: 'my-package', language: 'javascript' })
.withOptions({ skipInstall: true }),
);

it('creates files', () => {
}));

test('generator-superset:package:creates javascript files', () =>
helpers
.run(packageModule)
.inTmpDir(function (dir) {
// `dir` is the path to the new temporary directory
fs.copySync(path.join(__dirname, '../generators/package'), dir);
})
.withPrompts({ name: 'my-package', language: 'javascript' })
.withOptions({ skipInstall: true })
.then(function () {
assert.file([
'package.json',
'README.md',
'src/index.js',
'test/index.test.js',
]);
});
});
});
}));
Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,37 @@
const path = require('path');
const assert = require('yeoman-assert');
const helpers = require('yeoman-test');
const fs = require('fs-extra');
const pluginChartModule = require('../generators/plugin-chart');

describe('generator-superset:plugin-chart', () => {
let dir;

beforeAll(() => {
dir = process.cwd();

return helpers
.run(path.join(__dirname, '../generators/plugin-chart'))
.withPrompts({ packageName: 'cold-map', description: 'Cold Map' })
.withOptions({ skipInstall: true });
});

/*
* Change working directory back to original working directory
* after the test has completed.
* yeoman tests switch to tmp directory and write files there.
* Usually this is fine for solo package.
* However, for a monorepo like this one,
* it made jest confuses with current directory
* (being in tmp directory instead of superset-ui root)
* and interferes with other tests in sibling packages
* that are run after the yeoman tests.
*/
afterAll(() => {
process.chdir(dir);
});

it('creates files', () => {
assert.file([
'package.json',
'README.md',
'src/plugin/buildQuery.ts',
'src/plugin/controlPanel.ts',
'src/plugin/index.ts',
'src/plugin/transformProps.ts',
'src/ColdMap.tsx',
'src/index.ts',
'test/index.test.ts',
'test/plugin/buildQuery.test.ts',
'test/plugin/transformProps.test.ts',
'types/external.d.ts',
'src/images/thumbnail.png',
]);
});
});
test('generator-superset:plugin-chart:creates files', () =>
helpers
.run(pluginChartModule)
.inTmpDir(function (dir) {
// `dir` is the path to the new temporary directory
fs.copySync(path.join(__dirname, '../generators/plugin-chart'), dir);
})
.withPrompts({
packageName: 'cold-map',
description: 'Cold Map',
componentType: 'function',
chartType: 'regular',
})
.withOptions({ skipInstall: true })
.then(function () {
assert.file([
'package.json',
'README.md',
'src/plugin/buildQuery.ts',
'src/plugin/controlPanel.ts',
'src/plugin/index.ts',
'src/plugin/transformProps.ts',
'src/ColdMap.tsx',
'src/index.ts',
'test/index.test.ts',
'test/plugin/buildQuery.test.ts',
'test/plugin/transformProps.test.ts',
'types/external.d.ts',
'src/images/thumbnail.png',
]);
}));
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"composite": false,
"emitDeclarationOnly": false,
"noEmit": true,
"rootDir": "."
"rootDir": ".."
},
"extends": "../../../tsconfig.json",
"include": [
Expand Down

0 comments on commit c539787

Please sign in to comment.