diff --git a/jest-puppeteer.config.js b/jest-puppeteer.config.js index f07d6a0..5eb04b0 100644 --- a/jest-puppeteer.config.js +++ b/jest-puppeteer.config.js @@ -1,6 +1,5 @@ module.exports = { launch: { - headless: true, - slowMo: 30 + headless: false } }; \ No newline at end of file diff --git a/scraper.test.js b/scraper.test.js index e0e54e0..941b73e 100644 --- a/scraper.test.js +++ b/scraper.test.js @@ -1,12 +1,45 @@ +const puppeteer = require('puppeteer'); require('expect-puppeteer'); -describe( 'Google', () => { - beforeAll( async () => { - await page.goto('https://www.sports-reference.com/cfb/schools/utah/2022-schedule.html', { waitUntil: 'domcontentloaded' }); +describe( 'Utes Web Scraper', () => { + + describe( 'Utes 2022 Schedule', () => { + it( 'should open the schedule page, and match title.', async () => { + await page.goto('https://www.sports-reference.com/cfb/schools/utah/2022-schedule.html', { waitUntil: 'domcontentloaded' }); + expect(page.title()).resolves.toMatch("2022 Utah Utes Schedule and Results | College Football at Sports-Reference.com"); + } ); + + it( 'should get the Utes opponents/games for 2022', async () => { + let results = await page.evaluate( () => { + let team = { + opponents: [], + dates: [] + }; + let opponents = document.querySelectorAll( '#schedule td[data-stat="opp_name"]' ); + let dates = document.querySelectorAll( '#schedule td[data-stat="date_game"]' ); + dates.forEach( (dates) => team.dates.push(dates.textContent) ); + opponents.forEach( opponent => team.opponents.push( opponent.textContent ) ); + return team; + } ); + expect( results.dates[0] ).toBe( 'Sep 3, 2022' ); + expect( results.opponents[0] ).toBe( 'Florida' ); + expect( results.opponents.length ).toBe( 12 ); + } ); } ); - it( 'should open a new page, and match title.', async () => { - const title = await page.title(); - expect(title).toMatch("2022 Utah Utes Schedule and Results | College Football at Sports-Reference.com"); + describe( 'Utes 2021 Stats', () => { + it( 'should open the stats page, and match title.', async () => { + await page.goto('https://www.sports-reference.com/cfb/schools/utah/2021.html', { waitUntil: 'domcontentloaded' }); + expect(page.title()).resolves.toMatch("2021 Utah Utes Stats | College Football at Sports-Reference.com"); + } ); } ); + + describe( 'Utes 2022 Stats', () => { + it( 'should open the stats page, and match title.', async () => { + await page.goto('https://www.sports-reference.com/cfb/schools/utah/2022.html', { waitUntil: 'domcontentloaded' }); + expect(page.title()).resolves.toMatch("2022 Utah Utes Stats | College Football at Sports-Reference.com"); + } ); + } ); + + // it ( 'should open') } ); \ No newline at end of file