1
- import { getWebsiteRank } from "../dist/rank.mjs " ;
1
+ import esmock from "esmock " ;
2
2
3
3
describe ( "rank a website in Google Search" , function ( ) {
4
- this . retries ( 3 ) ;
5
- this . timeout ( 20000 ) ;
4
+ const mockImport = ( ) =>
5
+ esmock ( "../dist/rank.mjs" , {
6
+ [ "google-sr" ] : {
7
+ searchWithPages : async ( { query, pages } ) => {
8
+ if ( query !== "google" ) return [ ] ;
9
+ const websitesPages = [
10
+ [
11
+ "https://www.google.com/?hl=id" ,
12
+ "https://www.google.co.id/?hl=id" ,
13
+ "https://accounts.google.com/login?hl=id" ,
14
+ "https://play.google.com/store/apps/details?id=com.google.android.googlequicksearchbox&hl=en_US" ,
15
+ "https://myaccount.google.com/privacy?hl=id" ,
16
+ "https://accounts.google.com/" ,
17
+ "https://myaccount.google.com/intro/personal-info?hl=id" ,
18
+ "https://id.wikipedia.org/wiki/Google" ,
19
+ ] ,
20
+ [
21
+ "https://twitter.com/Google" ,
22
+ "https://accounts.google.com/" ,
23
+ "https://www.youtube.com/user/google" ,
24
+ "https://www.instagram.com/googleindonesia/" ,
25
+ "https://news.google.com/?hl=ID" ,
26
+ "https://about.google/" ,
27
+ "https://blog.google/" ,
28
+ "https://store.google.com/" ,
29
+ "https://support.google.com/" ,
30
+ "https://www.facebook.com/Google/?locale=id_ID" ,
31
+ ] ,
32
+ [
33
+ "https://www.facebook.com/Google/?locale=id_ID" ,
34
+ "https://io.google/" ,
35
+ "https://www.google.co.uk/" ,
36
+ "https://myactivity.google.com/" ,
37
+ "https://apps.google.com/meet/" ,
38
+ "https://one.google.com/about" ,
39
+ "https://bard.google.com/?hl=in" ,
40
+ "https://ads.google.com/intl/id_id/home/" ,
41
+ "https://classroom.google.com/" ,
42
+ ] ,
43
+ ] ;
44
+ return websitesPages . slice ( 0 , pages ) . map ( ( websites ) => {
45
+ return websites . map ( ( website ) => ( {
46
+ type : "SEARCH" ,
47
+ link : website ,
48
+ } ) ) ;
49
+ } ) ;
50
+ } ,
51
+ } ,
52
+ } ) ;
6
53
7
54
it ( "should rank a website that is found" , async ( ) => {
8
- const prom = getWebsiteRank ( "github.com" , "googlethis" ) ;
55
+ const { getWebsiteRank } = await mockImport ( ) ;
56
+ const prom = getWebsiteRank ( "google.com" , "google" ) ;
9
57
return prom . should . eventually . not . to . be . undefined . and . then (
10
58
( { page, rank } ) => {
11
59
page . should . be . equal ( 0 ) ;
@@ -15,12 +63,14 @@ describe("rank a website in Google Search", function () {
15
63
} ) ;
16
64
17
65
it ( "should not rank a website that is not found" , async ( ) => {
18
- const prom = getWebsiteRank ( "randomsite.con" , "googlethis" ) ;
66
+ const { getWebsiteRank } = await mockImport ( ) ;
67
+ const prom = getWebsiteRank ( "randomsite.con" , "google" ) ;
19
68
return prom . should . eventually . to . be . undefined ;
20
69
} ) ;
21
70
22
71
it ( "should rank a website that is found on a specific page" , async ( ) => {
23
- const prom = getWebsiteRank ( "facebook.com" , "googlethis" , { maxPage : 10 } ) ;
72
+ const { getWebsiteRank } = await mockImport ( ) ;
73
+ const prom = getWebsiteRank ( "facebook.com" , "google" , { maxPage : 3 } ) ;
24
74
return prom . should . eventually . not . to . be . undefined . and . then (
25
75
( { page, rank } ) => {
26
76
page . should . be . above ( 0 ) ;
0 commit comments