Skip to content

Commit

Permalink
Merge pull request #53 from curbengh/refactor-test
Browse files Browse the repository at this point in the history
refactor(test): reset config with beforeEach()
  • Loading branch information
curbengh authored Aug 15, 2020
2 parents b87a675 + 19ed3ba commit 2b23c05
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
'use strict';

const should = require('chai').should(); // eslint-disable-line
require('chai').should();
const Hexo = require('hexo');

describe('Stylus renderer', () => {
const hexo = new Hexo(__dirname, {silent: true});
const ctx = Object.assign(hexo, {
config: {
stylus: {
compress: false
}
const defaultCfg = JSON.parse(JSON.stringify(Object.assign(hexo.config, {
stylus: {
compress: false
}
})));
const themeCfg = JSON.parse(JSON.stringify(Object.assign(hexo.theme.config, {
foo: 1,
bar: {
baz: 2
},
theme: {
config: {
foo: 1,
bar: {
baz: 2
},
nil: null,
obj: {
arr: [1, 2, 3]
}
}
nil: null,
obj: {
arr: [1, 2, 3]
}
});
})));

const r = require('../lib/renderer').bind(ctx);
const r = require('../lib/renderer').bind(hexo);

beforeEach(() => {
hexo.config = JSON.parse(JSON.stringify(defaultCfg));
hexo.theme.config = JSON.parse(JSON.stringify(themeCfg));
});

it('no config', () => {
const body = [
'.foo',
' color: red'
].join('\n');
const config = ctx.config.stylus;

ctx.config.stylus = null;
hexo.config.stylus = {};
r({text: body}, {}, (err, result) => {
if (err) throw err;

ctx.config.stylus = config;
result.should.eql([
'.foo {',
' color: #f00;',
Expand All @@ -65,7 +64,7 @@ describe('Stylus renderer', () => {
});

it('compress', () => {
ctx.config.stylus.compress = true;
hexo.config.stylus.compress = true;

const body = [
'.foo',
Expand All @@ -75,7 +74,6 @@ describe('Stylus renderer', () => {
r({text: body}, {}, (err, result) => {
if (err) throw err;

ctx.config.stylus.compress = false;
result.should.eql('.foo{color:#f00}');
});
});
Expand Down Expand Up @@ -181,5 +179,4 @@ describe('Stylus renderer', () => {
});
});
});

});

0 comments on commit 2b23c05

Please sign in to comment.