-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatabase.js
66 lines (56 loc) · 1.74 KB
/
database.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const { info, execa } = require('@vue/cli-shared-utils');
const path = require('path');
const managePy = require('./managepy');
/**
* Represents database used during the e2e tests
*/
let instance = null;
class Database {
constructor({ djangopath, DJANGO_DATABASE_NAME, BACKEND_PORT, DJANGO_CONFIGURATION }) {
if(!instance){
instance = this;
}
this.djangopath = djangopath;
this.databasename = DJANGO_DATABASE_NAME;
this.backend_port = BACKEND_PORT;
this.django_configuration = DJANGO_CONFIGURATION
process.env.DJANGO_DATABASE_NAME = this.databasename;
process.env.djangopath = this.djangopath;
process.env.BACKEND_PORT = this.backend_port;
process.env.DJANGO_CONFIGURATION = this.django_configuration;
return instance;
}
async create() {
try {
info(`Creating database: '${this.databasename}'...`);
await execa('./bin/e2e_setup_db', [this.databasename], { cwd: this.djangopath });
} catch (e) {
if (!e.message.includes('already exists')) {
throw e;
}
}
}
async reset() {
info(`Resetting database: '${this.databasename}'...`);
return execa('./bin/e2e_reload_db', [this.databasename], { cwd: this.djangopath });
}
async drop() {
info(`Dropping database: '${this.databasename}'...`);
return execa('./bin/e2e_teardown_db', [this.databasename], { cwd: this.djangopath });
}
async load(dataset) {
info(`Loading fixtures for ${dataset}`);
return managePy(
this.djangopath,
['load_e2e_data', '--datasets', dataset],
{
stdout: 'inherit',
env: {
BACKEND_PORT: this.backend_port,
DJANGO_CONFIGURATION: this.django_configuration,
},
},
);
}
}
module.exports = Database;