Skip to content

Commit

Permalink
chore: upgrade lab to v15
Browse files Browse the repository at this point in the history
Signed-off-by: Robinson Rodriguez <rfrodriguez1992@gmail.com>
  • Loading branch information
rfrm committed Apr 6, 2020
1 parent 18317cf commit c0579b4
Show file tree
Hide file tree
Showing 11 changed files with 374 additions and 810 deletions.
652 changes: 196 additions & 456 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"dotenv": "^5.0.1",
"final-fs": "^1.6.0",
"inflection": "^1.10.0",
"lab": "15.x",
"mkdirp": "~0.5.0",
"parse-database-url": "~0.3.0",
"prompt": "^1.0.0",
Expand All @@ -71,7 +72,6 @@
"eslint-plugin-node": "^8.0.1",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"lab": "^14.3.1",
"proxyquire": "^1.4.0",
"rimraf": "^2.6.2",
"sinon": "^7.2.2"
Expand Down
94 changes: 24 additions & 70 deletions test/config_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,21 @@ lab.experiment('config', function () {
var configPath = path.join(__dirname, 'database.json');
var _config = config.load(configPath, 'dev');

lab.test(
'should export all environment settings',

function (done) {
Code.expect(_config.dev).to.exists();
Code.expect(_config.test).to.exists();
Code.expect(_config.prod).to.exists();
done();
}
);
lab.test('should export all environment settings', () => {
Code.expect(_config.dev).to.exists();
Code.expect(_config.test).to.exists();
Code.expect(_config.prod).to.exists();
});

lab.test(
'should export a getCurrent function with all current ' +
'environment settings',

function (done) {
'environment settings', () => {
var current;
Code.expect(_config.getCurrent).to.exists();
current = _config.getCurrent();
Code.expect(current.env).to.equal('dev');
Code.expect(current.settings.driver).to.equal('sqlite3');
Code.expect(current.settings.filename).to.equal(':memory:');
done();
}
);
});
Expand All @@ -45,12 +37,11 @@ lab.experiment('config', function () {
function () {
var configPath = path.join(__dirname, 'database_with_syntax_error.json');

lab.test('should throw a syntax error', function (done) {
lab.test('should throw a syntax error', async () => {
Code.expect(
config.load.bind(this, configPath, 'dev'),
'Expected broken file to produce syntax error'
).to.throw(SyntaxError);
done();
});
}
);
Expand All @@ -63,14 +54,11 @@ lab.experiment('config', function () {
var _config = config.load(configPath);

lab.test(
'should load a value from the default env',

function (done) {
'should load a value from the default env', () => {
var current = _config.getCurrent();
Code.expect(current.env).to.equal('local');
Code.expect(current.settings.driver).to.equal('sqlite3');
Code.expect(current.settings.filename).to.equal(':memory:');
done();
}
);
}
Expand All @@ -88,13 +76,10 @@ lab.experiment('config', function () {
var _config = config.load(configPath);

lab.test(
'should load a value from the env set in NODE_ENV',

function (done) {
'should load a value from the env set in NODE_ENV', () => {
var current = _config.getCurrent();
Code.expect(current.settings.driver).to.equal('sqlite3');
Code.expect(current.settings.filename).to.equal(':memory:');
done();
}
);
}
Expand All @@ -109,11 +94,8 @@ lab.experiment('config', function () {
var _config = config.load(configPath, 'prod');

lab.test(
'should load a value from the environments',

function (done) {
'should load a value from the environments', () => {
Code.expect(_config.prod.username).to.equal('username_from_env');
done();
}
);
}
Expand All @@ -128,16 +110,13 @@ lab.experiment('config', function () {
var _config = config.load(configPath, 'prod');

lab.test(
'should load a value from the environments',

function (done) {
'should load a value from the environments', () => {
var current = _config.getCurrent();
Code.expect(current.settings.driver).to.equal('postgres');
Code.expect(current.settings.user).to.equal('uname');
Code.expect(current.settings.password).to.equal('pw');
Code.expect(current.settings.host).to.equal('server.com');
Code.expect(current.settings.database).to.equal('dbname');
done();
}
);
}
Expand All @@ -148,19 +127,14 @@ lab.experiment('config', function () {
var _config = config.loadUrl(databaseUrl, 'dev');

lab.test(
'should export the settings as the current environment',

function (done) {
'should export the settings as the current environment', () => {
Code.expect(_config.dev).to.exists();
done();
}
);

lab.test(
'should export a getCurrent function with all current ' +
'environment settings',

function (done) {
'environment settings', () => {
var current;
Code.expect(_config.getCurrent).to.exists();
current = _config.getCurrent();
Expand All @@ -170,7 +144,6 @@ lab.experiment('config', function () {
Code.expect(current.settings.password).to.equal('pw');
Code.expect(current.settings.host).to.equal('server.com');
Code.expect(current.settings.database).to.equal('dbname');
done();
}
);
});
Expand All @@ -180,14 +153,13 @@ lab.experiment('config', function () {
config.load = _configLoad;
config.loadUrl = _configLoadUrl;

lab.test('should something', function (done) {
lab.test('should something', () => {
Code.expect(config.load.bind(this, configPath, 'dev')).to.not.throw();
done();
});
});

lab.experiment('loading a url from url property', function () {
lab.test('should export a valid config', function (done) {
lab.test('should export a valid config', () => {
var databaseUrl = {
dev: {
url: 'postgres://uname:pw@server.com/dbname'
Expand All @@ -204,13 +176,9 @@ lab.experiment('config', function () {
Code.expect(current.settings.password).to.equal('pw');
Code.expect(current.settings.host).to.equal('server.com');
Code.expect(current.settings.database).to.equal('dbname');

done();
});

lab.test('should export the value if specified in suboject', function (
done
) {
lab.test('should export the value if specified in suboject', () => {
var databaseUrl = {
dev: {
url: {
Expand All @@ -224,8 +192,6 @@ lab.experiment('config', function () {
var current = cfg.getCurrent();
Code.expect(current.env).to.equal('dev');
Code.expect(current.settings.url).to.equal('http://example.com');

done();
});
});

Expand All @@ -241,16 +207,12 @@ lab.experiment('config', function () {

var cfg = config.loadObject(databaseUrl, 'dev');

lab.test('should export the settings as the current environment', function (
done
) {
lab.test('should export the settings as the current environment', () => {
Code.expect(cfg.dev).to.exists();
done();
});

lab.test(
'should export a getCurrent function with all current environment settings',
function (done) {
'should export a getCurrent function with all current environment settings', () => {
Code.expect(cfg.getCurrent).to.exists();
var current = cfg.getCurrent();
Code.expect(current.env).to.equal('dev');
Expand All @@ -262,8 +224,6 @@ lab.experiment('config', function () {
Code.expect(current.settings.host).to.equal('server.com');
Code.expect(current.settings.database).to.equal('dbname');
Code.expect(current.settings.ssl).to.equal(true);

done();
}
);
});
Expand All @@ -273,7 +233,7 @@ lab.experiment('config', function () {
function () {
lab.test(
'should export a getCurrent function with all current environment settings',
function (done, cleanup) {
function (flags) {
process.env.DATABASE_URL = 'postgres://uname:pw@server.com/dbname';
var databaseUrl = {
dev: {
Expand All @@ -285,10 +245,9 @@ lab.experiment('config', function () {
};
var cfg = config.loadObject(databaseUrl, 'dev');

cleanup(function (next) {
flags.onCleanup = () => {
delete process.env.DATABASE_URL;
next();
});
};

Code.expect(cfg.getCurrent).to.exists();
var current = cfg.getCurrent();
Expand All @@ -301,8 +260,6 @@ lab.experiment('config', function () {
Code.expect(current.settings.host).to.equal('server.com');
Code.expect(current.settings.database).to.equal('dbname');
Code.expect(current.settings.ssl).to.equal(true);

done();
}
);
}
Expand All @@ -311,7 +268,7 @@ lab.experiment('config', function () {
lab.experiment(
'loading from an ENV URL within the object and extending it from the ENV',
function () {
lab.test('', function (done, cleanup) {
lab.test('', function (flags) {
process.env.DATABASE_URL =
'postgres://uname:pw@server.com/dbname?ssl=false&testing=false';
var databaseUrl = {
Expand All @@ -332,10 +289,9 @@ lab.experiment('config', function () {
};
var cfg = config.loadObject(databaseUrl, 'dev');

cleanup(function (next) {
flags.onCleanup = () => {
delete process.env.DATABASE_URL;
next();
});
};

Code.expect(cfg.getCurrent).to.exists();
var current = cfg.getCurrent();
Expand All @@ -352,8 +308,6 @@ lab.experiment('config', function () {
Code.expect(current.settings.testing).to.equal('false');
Code.expect(current.settings.cache).to.equal(false);
Code.expect(current.settings.ssl).to.equal(true);

done();
});
}
);
Expand Down
10 changes: 3 additions & 7 deletions test/driver/base_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ lab.experiment('base', function () {
lab.experiment('default implementation', function () {
var base = new Base(internals);

lab.test('inherits from EventEmitter', function (done) {
lab.test('inherits from EventEmitter', () => {
Code.expect(base.on).to.be.not.null();
Code.expect(base.emit).to.be.not.null();
done();
});

lab.test('throws errors for all API methods', function (done) {
lab.test('throws errors for all API methods', () => {
Code.expect(function () {
base.createTable();
}).to.throw(Error);
Expand Down Expand Up @@ -77,15 +76,12 @@ lab.experiment('base', function () {
Code.expect(function () {
base.runSql();
}).to.throw(Error);

done();
});

lab.test('escapes single quotes', function (done) {
lab.test('escapes single quotes', () => {
Code.expect("Bill''s Mother''s House").to.equal(
base.escape("Bill's Mother's House")
);
done();
});
});
});
Loading

0 comments on commit c0579b4

Please sign in to comment.