-
Notifications
You must be signed in to change notification settings - Fork 54
/
index.spec.mjs
executable file
路203 lines (191 loc) 路 7.19 KB
/
index.spec.mjs
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import assert from 'node:assert';
import { resolve } from 'node:path';
import { createRequire } from 'module';
import dedupe from '../build/dedupe.mjs';
const require = createRequire(import.meta.url);
const itemPath = resolve('./index.js');
const importFresh = async (path) => {
return (await import(`${path}?update=${Date.now()}`)).default;
};
let Items;
const inits = [];
const wrapConstr = async (opts) => {
const before = Date.now();
const items = new Items(opts);
const after = Date.now();
inits.push(after - before);
return items;
};
Items = await importFresh(itemPath);
const data = Object.freeze({
items: await wrapConstr(),
warframes: await wrapConstr({ category: ['Warframes', 'Archwing'], i18n: 'en', i18nOnObject: true }),
weapons: await wrapConstr({
category: ['Primary', 'Secondary', 'Melee', 'Arch-Melee', 'Arch-Gun'],
i18n: 'en',
i18nOnObject: true,
}),
});
const namedExclusions = ['Excalibur Prime'];
describe('index.js', () => {
beforeEach(async () => {
delete require.cache[itemPath];
Items = await importFresh(itemPath);
});
it('should contain items when initializing.', () => {
const items = new Items();
assert(items.length);
});
it('should ignore enemies when configured.', async () => {
let items = (await wrapConstr({ ignoreEnemies: true })).filter((i) => i.category === 'Enemy');
assert(!items.length);
items = (await wrapConstr({ category: ['Enemy', 'Primary'], ignoreEnemies: true })).filter(
(i) => i.category === 'Enemy'
);
assert(!items.length);
});
it('should construct successfully with all & primary', async () => {
const items = await wrapConstr({ category: ['Primary', 'All'] });
assert(items.length > 0);
});
it('should not error current worldstate-data supported locales', async () => {
try {
await wrapConstr({
i18n: ['de', 'es', 'fr', 'it', 'ko', 'pl', 'pt', 'ru', 'zh', 'cs', 'sr'],
i18nOnObject: true,
});
} catch (e) {
assert(typeof e === 'undefined');
}
});
it('does not fail on invalid categories', () => {
assert.doesNotThrow(() => {
new Items({ category: 'Warframe' });
});
});
it('should apply custom categories are specified', async () => {
const items = await wrapConstr({ category: ['Primary'] });
const primes = items.filter((i) => i.name.includes('Prime'));
assert(primes.length < items.length);
});
describe('i18n', () => {
it('should populate with a truthy boolean', async () => {
const items = await wrapConstr({ category: ['Mods'], i18n: ['es', 'tr'] });
assert(!!items.i18n[items[0].uniqueName].tr);
assert(!!items.i18n[items[0].uniqueName].es);
});
it('should not exist by default', async () => {
const items = await wrapConstr();
assert(!items.i18n);
});
it('should only contain requested locales', async () => {
const items = await wrapConstr({ category: ['Mods'], i18n: ['es'] });
assert(!items.i18n[items[0].uniqueName].tr);
assert(!!items.i18n[items[0].uniqueName].es);
});
it('should respect itemOnObject', async () => {
const items = await wrapConstr({ category: ['Mods'], i18n: ['es'], i18nOnObject: true });
assert(!items[0].i18n.tr);
assert(!!items[0].i18n.es);
assert(!items.i18n);
});
});
describe('drops', () => {
it('should not have drops for hikou', async () => {
const items = await wrapConstr({ category: ['Secondary'] });
const hikouMatches = items.filter((i) => i.name === 'Hikou');
assert(hikouMatches.length === 1);
const { drops } = hikouMatches[0];
assert(typeof drops === 'undefined');
});
it('should only have non-prime drops for Gorgon', async () => {
const items = await wrapConstr({ category: ['Primary'] });
const matches = items.filter((i) => i.name === 'Gorgon');
assert(matches.length === 1);
const { drops } = matches[0];
assert(typeof drops === 'undefined');
const bp = matches[0].components.filter((component) => component.name === 'Blueprint')[0];
assert(typeof bp !== 'undefined');
assert(bp.drops.length !== 0);
const primeBpDrops = bp.drops.filter((n) => n.type.includes('Prime'));
assert(primeBpDrops.length === 0);
});
it('should have variant drops when requested', async () => {
const items = await wrapConstr({ category: ['Primary'] });
const matches = items.filter((i) => i.name === 'Gorgon Wraith');
assert(matches.length === 1);
const { drops } = matches[0];
assert(typeof drops === 'undefined');
const bp = matches[0].components.filter((component) => component.name === 'Blueprint')[0];
assert(typeof bp !== 'undefined');
assert(bp.drops.length !== 0);
const variantDrops = bp.drops.filter((n) => n.type.includes('Wraith'));
assert(variantDrops.length === 1);
});
it('should only have 1 result for Mausolon', async () => {
const items = await wrapConstr({ category: ['Arch-Gun'] });
const matches = items
.filter((i) => i.name === 'Mausolon')
.map((i) => {
delete i.patchlogs;
return i;
});
const dd = dedupe(matches);
assert.strictEqual(dd.length, matches.length, 'Before and after dedupe should match');
assert.strictEqual(matches.length, 1, 'There can be only One');
});
});
});
describe('integrity', function () {
this.timeout(10000);
it('weapons should only have 1 result for Mausolon', () => {
const matches = data.weapons
.filter((i) => i.name === 'Mausolon')
.map((i) => {
delete i.patchlogs;
return i;
});
const dd = dedupe(matches);
assert.strictEqual(dd.length, matches.length, 'Before and after dedupe should match');
assert.strictEqual(matches.length, 1, 'There can be only One');
});
it('warframes should only have 1 result for Octavia Prime', () => {
const matches = data.warframes
.filter((i) => i.name === 'Octavia Prime')
.map((i) => {
delete i.patchlogs;
return i;
});
const dd = dedupe(matches);
assert.strictEqual(dd.length, matches.length, 'Before and after dedupe should match');
assert.strictEqual(matches.length, 1, 'There can be only One');
});
it('items should only have 1 result for Octavia Prime', () => {
const matches = data.items
.filter((i) => i.name === 'Octavia Prime')
.map((i) => {
delete i.patchlogs;
return i;
});
const dd = dedupe(matches);
assert.strictEqual(dd.length, matches.length, 'Before and after dedupe should match');
assert.strictEqual(matches.length, 1, 'There can be only One');
assert(Object.keys(matches[0]).includes('components'));
});
describe('melee check', () => {
data.items
.filter((i) => ['Amphis', 'Cadus', 'Cassowar', 'Caustacyst', 'Sigma & Octantis'].includes(i.name))
.forEach((item) => {
it(`${item.name} should be melee`, () => {
assert.equal(item.type, 'Melee');
});
});
});
data.warframes
.filter((w) => !namedExclusions.includes(w.name))
.forEach((warframe) => {
it(`${warframe.name} should have components`, () => {
assert(warframe?.components?.length > 0);
});
});
});