|
1 | | -import fs from 'fs/promises'; |
2 | | -import disposableEmailDetector from "../index" |
3 | | -import path from 'path'; |
| 1 | +import fs from "fs/promises"; |
| 2 | +import disposableEmailDetector from "../index"; |
| 3 | +import path from "path"; |
4 | 4 |
|
5 | 5 | // Load test emails from file |
6 | | -const filePath: string = path.join(__dirname, './testEmails.txt'); |
| 6 | +const filePath: string = path.join(__dirname, "./testEmails.txt"); |
7 | 7 |
|
8 | 8 | async function loadTestEmails(filePath: string): Promise<string[]> { |
9 | | - const rawData = await fs.readFile(filePath); |
10 | | - return rawData.toString().trim().split('\n'); |
| 9 | + const rawData = await fs.readFile(filePath); |
| 10 | + return rawData.toString().trim().split("\n"); |
11 | 11 | } |
12 | 12 |
|
13 | 13 | async function runTests() { |
14 | 14 | try { |
15 | | - const testEmails = await loadTestEmails(filePath); |
| 15 | + const testEmails = await loadTestEmails(filePath); |
16 | 16 |
|
17 | | - for (const email of testEmails) { |
18 | | - const isDisposable = await disposableEmailDetector(email); |
19 | | - console.log(email, '- Disposable:', isDisposable); |
20 | | - } |
21 | | - console.log('Test passed.'); |
| 17 | + for (const email of testEmails) { |
| 18 | + const isDisposable = await disposableEmailDetector(email); |
| 19 | + console.log(email, "- Disposable:", isDisposable); |
| 20 | + } |
| 21 | + console.log("Test passed."); |
| 22 | + } catch (error: any) { |
| 23 | + console.error("Unexpected error:", error); |
| 24 | + console.error("Please check the file path and try again."); |
| 25 | + console.error("Test failed."); |
| 26 | + } |
22 | 27 | } |
23 | | -catch (error: any) { |
24 | | - console.error('Unexpected error:', error); |
25 | | - console.error('Please check the file path and try again.'); |
26 | | - console.error('Test failed.'); |
| 28 | + |
| 29 | +async function runTestsExternalGithub() { |
| 30 | + try { |
| 31 | + const testEmails = await loadTestEmails(filePath); |
| 32 | + |
| 33 | + for (const email of testEmails) { |
| 34 | + const isDisposable = await disposableEmailDetector(email, { |
| 35 | + loadFromSource: { github: true }, |
| 36 | + }); |
| 37 | + console.log(email, "- Disposable:", isDisposable); |
| 38 | + } |
| 39 | + console.log("External: Github Test passed."); |
| 40 | + } catch (error: any) { |
| 41 | + console.error("Unexpected error:", error); |
| 42 | + console.error("Please check the github repository for index.json and try again."); |
| 43 | + console.error("Test failed."); |
| 44 | + } |
27 | 45 | } |
28 | 46 |
|
| 47 | +async function runTestsExternalURL() { |
| 48 | + try { |
| 49 | + const testEmails = await loadTestEmails(filePath); |
29 | 50 |
|
| 51 | + for (const email of testEmails) { |
| 52 | + const isDisposable = await disposableEmailDetector(email, { |
| 53 | + loadFromSource: { url: "https://pastebin.com/raw/HL70DeZg" }, |
| 54 | + }); |
| 55 | + console.log(email, "- Disposable:", isDisposable); |
| 56 | + } |
| 57 | + console.log("External: URL Test passed."); |
| 58 | + } catch (error: any) { |
| 59 | + console.error("Unexpected error:", error); |
| 60 | + console.error("Please check the URL and try again."); |
| 61 | + console.error("Test failed."); |
| 62 | + } |
30 | 63 | } |
31 | 64 |
|
32 | 65 | runTests(); |
| 66 | +runTestsExternalGithub(); |
| 67 | +runTestsExternalURL(); |
0 commit comments