mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-22 09:32:41 +00:00
feat: tests
This commit is contained in:
@@ -13,18 +13,15 @@
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {expect} from 'chai';
|
||||
import {suite, test} from '@testdeck/mocha';
|
||||
import {
|
||||
deleteUndefinedProperties,
|
||||
isNodeEnvironment,
|
||||
isProductiveEnvironment,
|
||||
isProductiveNodeEnvironment,
|
||||
} from '../src/common.js';
|
||||
} from '../src/index.js';
|
||||
|
||||
@suite()
|
||||
export class CommonSpec {
|
||||
@test
|
||||
deleteUndefinedProperties1() {
|
||||
describe('common', function () {
|
||||
it('should should delete undefined properties (1)', function () {
|
||||
expect(
|
||||
deleteUndefinedProperties({
|
||||
a: 2,
|
||||
@@ -39,20 +36,18 @@ export class CommonSpec {
|
||||
c: 3,
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@test
|
||||
deleteUndefinedProperties2() {
|
||||
it('should delete undefined properties (2)', function () {
|
||||
expect(
|
||||
deleteUndefinedProperties({
|
||||
a: undefined,
|
||||
b: undefined,
|
||||
}),
|
||||
).to.deep.equal({});
|
||||
}
|
||||
});
|
||||
|
||||
@test
|
||||
deleteUndefinedProperties3() {
|
||||
it('should delete undefined properties (3)', function () {
|
||||
expect(
|
||||
deleteUndefinedProperties({
|
||||
a: 2,
|
||||
@@ -64,49 +59,41 @@ export class CommonSpec {
|
||||
b: 'foo',
|
||||
c: 'bar',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@test
|
||||
isNodeEnvironment() {
|
||||
it('should detect node environment', function () {
|
||||
expect(isNodeEnvironment()).to.be.equal(true);
|
||||
|
||||
const savedProcess = process;
|
||||
|
||||
// @ts-ignore
|
||||
// @ts-expect-error override this
|
||||
process = undefined;
|
||||
|
||||
expect(isNodeEnvironment()).to.be.equal(false);
|
||||
|
||||
process = savedProcess;
|
||||
}
|
||||
});
|
||||
|
||||
@test
|
||||
isProductiveEnvironment() {
|
||||
const nodeEnv = process.env.NODE_ENV;
|
||||
it('should detect production environment', function () {
|
||||
const nodeEnvironment = process.env.NODE_ENV;
|
||||
|
||||
process.env.NODE_ENV = '';
|
||||
|
||||
expect(isProductiveEnvironment()).to.be.equal(false);
|
||||
|
||||
process.env.NODE_ENV = 'production';
|
||||
|
||||
expect(isProductiveEnvironment()).to.be.equal(true);
|
||||
|
||||
process.env.NODE_ENV = nodeEnv;
|
||||
}
|
||||
process.env.NODE_ENV = nodeEnvironment;
|
||||
});
|
||||
|
||||
@test
|
||||
isProductiveNodeEnvironment() {
|
||||
const nodeEnv = process.env.NODE_ENV;
|
||||
it('should detect node production environment', function () {
|
||||
const nodeEnvironment = process.env.NODE_ENV;
|
||||
|
||||
process.env.NODE_ENV = '';
|
||||
|
||||
expect(isProductiveNodeEnvironment()).to.be.equal(false);
|
||||
|
||||
process.env.NODE_ENV = 'production';
|
||||
|
||||
expect(isProductiveNodeEnvironment()).to.be.equal(true);
|
||||
|
||||
process.env.NODE_ENV = nodeEnv;
|
||||
}
|
||||
}
|
||||
process.env.NODE_ENV = nodeEnvironment;
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user