Skip to content

Commit

Permalink
build(test): remove unused deps
Browse files Browse the repository at this point in the history
  • Loading branch information
rhahao committed Nov 8, 2023
1 parent 328fca8 commit 379bb27
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 47 deletions.
91 changes: 45 additions & 46 deletions test/01_standardParsing.test.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,67 @@
import fs from 'fs';
import * as path from 'path';
import fetch from 'node-fetch';
import { expect } from 'chai';
import { loadEPUB } from '../dist/node/index.js';

const list = JSON.parse(await fs.promises.readFile(new URL('./standardParsing/list.json', import.meta.url)));
const JW_CDN = 'https://app.jw-cdn.org/apis/pub-media/GETPUBMEDIALINKS?';

const fetchData = async (language, issue, pub) => {
let data = [];
let fixture = [];
let data = [];
let fixture = [];

const url =
JW_CDN +
new URLSearchParams({
langwritten: language,
pub,
fileformat: 'epub',
output: 'json',
issue,
});
const url =
JW_CDN +
new URLSearchParams({
langwritten: language,
pub,
fileformat: 'epub',
output: 'json',
issue,
});

const res = await fetch(url);
const res = await fetch(url);

if (res.status === 200) {
const result = await res.json();
const epubEntry = result.files[language].EPUB;
if (res.status === 200) {
const result = await res.json();
const epubEntry = result.files[language].EPUB;

const epubFile = epubEntry[0].file;
const epubUrl = epubFile.url;
const epubName = path.basename(epubUrl);
data = await loadEPUB({ url: epubUrl });
fixture = (await import(`./fixtures/${epubName.replace('.epub', '.js')}`)).default;
}
const epubFile = epubEntry[0].file;
const epubUrl = epubFile.url;
const epubName = path.basename(epubUrl);
data = await loadEPUB({ url: epubUrl });
fixture = (await import(`./fixtures/${epubName.replace('.epub', '.js')}`)).default;
}

return { data, fixture };
return { data, fixture };
};

describe('Testing Standard Parsing', () => {
for (let i = 0; i < list.length; i++) {
const { language, issue } = list[i];
for (let i = 0; i < list.length; i++) {
const { language, issue } = list[i];

describe(`Test loadEPUB function for ${language} language`, async () => {
it(`Parsing Meeting Workbook EPUB file`, async () => {
const { data, fixture } = await fetchData(language, issue, 'mwb');
describe(`Test loadEPUB function for ${language} language`, async () => {
it(`Parsing Meeting Workbook EPUB file`, async () => {
const { data, fixture } = await fetchData(language, issue, 'mwb');

for (let a = 0; a < fixture.length; a++) {
const week = fixture[a];
for (let [key, value] of Object.entries(week)) {
expect(data[a]).to.have.property(key).equal(value);
}
}
});
for (let a = 0; a < fixture.length; a++) {
const week = fixture[a];
for (let [key, value] of Object.entries(week)) {
expect(data[a]).to.have.property(key).equal(value);
}
}
});

it(`Parsing Watchtower Study EPUB file`, async () => {
const { data, fixture } = await fetchData(language, issue, 'w');
it(`Parsing Watchtower Study EPUB file`, async () => {
const { data, fixture } = await fetchData(language, issue, 'w');

for (let a = 0; a < fixture.length; a++) {
const week = fixture[a];
for (let [key, value] of Object.entries(week)) {
expect(data[a]).to.have.property(key).equal(value);
}
}
});
});
}
for (let a = 0; a < fixture.length; a++) {
const week = fixture[a];
for (let [key, value] of Object.entries(week)) {
expect(data[a]).to.have.property(key).equal(value);
}
}
});
});
}
});
1 change: 0 additions & 1 deletion test/02_enhancedParsing.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fs from 'fs';
import * as path from 'path';
import fetch from 'node-fetch';
import { expect } from 'chai';
import { loadEPUB } from '../dist/node/index.js';

Expand Down

0 comments on commit 379bb27

Please sign in to comment.