Skip to content

Commit

Permalink
test(theme): add case for local & installed theme
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachScript committed Jan 19, 2021
1 parent 29e669d commit 4a0e33f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 6 deletions.
6 changes: 1 addition & 5 deletions packages/preset-dumi/src/fixtures/local-theme/.umirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,5 @@ import path from 'path';

export default {
history: { type: 'memory' },
mountElementId: '',
chainWebpack(memo) {
// compile linked dumi-theme-default
memo.module.rule('js').include.add(path.join(__dirname, '../../../../theme-default'));
}
mountElementId: ''
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
4 changes: 4 additions & 0 deletions packages/preset-dumi/src/fixtures/progressive-theme/.umirc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default {
history: { type: 'memory' },
mountElementId: ''
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# dumi
33 changes: 32 additions & 1 deletion packages/preset-dumi/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('preset-dumi', () => {

afterAll(() => {
// clear all node_modules
['', 'basic', 'algolia', 'demos', 'assets', 'local-theme', 'integrate'].forEach(dir => {
['', 'basic', 'algolia', 'demos', 'assets', 'integrate', 'local-theme', 'progressive-theme', 'sitemap'].forEach(dir => {
rimraf.sync(path.join(fixtures, dir, 'node_modules'));
});
});
Expand Down Expand Up @@ -143,6 +143,37 @@ describe('preset-dumi', () => {
expect(await findByText('local theme layout')).not.toBeNull();
});

it('fallback for progressive theme', async () => {
const cwd = path.join(fixtures, 'progressive-theme');
const service = new Service({
cwd,
presets: [require.resolve('@umijs/preset-built-in'), require.resolve('./index.ts')],
});

// alias dumi-theme-default
symlink(
path.join(__dirname, '../../theme-default'),
path.join(service.paths.absNodeModulesPath, 'dumi-theme-default'),
);

// force use empty theme
process.env.DUMI_THEME = './.empty-theme';

await service.run({
name: 'g',
args: {
_: ['g', 'tmp'],
},
});

delete process.env.DUMI_THEME;

const reactNode = require(path.join(cwd, '.umi-test', 'umi.ts')).default;
const { findAllByText } = render(reactNode);

expect(await findAllByText('dumi')).not.toBeNull();
});

it('platform env', async () => {
const oType = process.env.PLATFORM_TYPE;

Expand Down

0 comments on commit 4a0e33f

Please sign in to comment.