Use a different database when running tests and package tests #12315
jankapunkt
started this conversation in
Feature Requests
Replies: 1 comment 2 replies
-
Currently we use for E2E testing random db name like this(meteor package):
import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
const USE_PACKAGE = process.env.RANDOM_DB_NAME;
if (Meteor.isDevelopment && USE_PACKAGE) {
if (process.env.MONGO_URL) {
const nowSeconds = Number.parseInt(new Date().getTime() / 1000);
let seconds = nowSeconds - 51 * 365 * 24 * 60 * 60;
if (seconds < 0) {
seconds = nowSeconds;
}
const randomString = `${seconds}${Random.secret(2)}`;
const newMongoUrl = process.env.MONGO_URL + randomString;
const newDBName = newMongoUrl.split('/').find(s => s.includes(randomString));
console.log(`itgenio/random-database: Use db name '${newDBName}'`);
process.env.MONGO_URL = newMongoUrl;
}
}
/* eslint-disable no-undef */
Package.describe({
name: 'itgenio:random-db-name',
version: '1.0.0',
summary: 'Create random db name',
documentation: 'README.md',
debugOnly: true,
});
Package.onUse(function (api) {
api.versionsFrom('[email protected]');
api.use(['ecmascript', 'random'], 'server');
api.mainModule('main.js', 'server');
}); how we run: But yeah, we need to reset some collections manually. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I observed again and again the same problems when testing
Would it be hard to create another database within the portable
mongo
service, maybe namedmeteortests
or something, which we canreset
before testing? That would reduce our test code by nearly half, which is mostly stubbing codeBeta Was this translation helpful? Give feedback.
All reactions