diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 1bf0a4c08..432648dc8 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -145,7 +145,11 @@ jobs: SLACK_WEBHOOK_MODS: ${{ secrets.SLACK_WEBHOOK_MODS }} - name: integration tests if: ${{ env.SCRATCH_SHOULD_DEPLOY == 'true' }} - run: JEST_JUNIT_OUTPUT_NAME=integration-jest-results.xml npm run test:integration:remote -- --reporters=jest-junit + run: | + # if the health test fails, there's no point in trying to run the integration tests + npm run test:health + # health test succeeded, so proceed with integration tests + JEST_JUNIT_OUTPUT_NAME=integration-jest-results.xml npm run test:integration -- --reporters=jest-junit env: ROOT_URL: ${{ secrets.ROOT_URL }} @@ -155,6 +159,7 @@ jobs: CIRCLE_BUILD_NUM: ${{ github.run_id }} # TODO SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }} SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }} + SMOKE_REMOTE: "true" # use Sauce Labs # test/integration/* SMOKE_USERNAME: ${{ secrets.SMOKE_USERNAME }} diff --git a/package.json b/package.json index ac4a9a47f..1aa6ec928 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,8 @@ "test": "npm run test:lint && npm run build && npm run test:unit", "test:lint": "eslint . --ext .js,.jsx,.json", "test:lint:ci": "eslint . --ext .js,.jsx,.json --format junit -o ./test/results/lint-results.xml", + "test:health": "jest ./test/health/*.test.js", "test:integration": "jest ./test/integration/*.test.js --reporters=default --maxWorkers=5", - "test:integration:remote": "SMOKE_REMOTE=true jest ./test/integration/*.test.js --reporters=default --maxWorkers=5", "test:unit": "npm run test:unit:jest && npm run test:unit:tap", "test:unit:jest": "npm run test:unit:jest:unit && npm run test:unit:jest:localization", "test:unit:jest:unit": "jest ./test/unit/ --reporters=default", diff --git a/test/health/server-health.test.js b/test/health/server-health.test.js new file mode 100644 index 000000000..19233b01d --- /dev/null +++ b/test/health/server-health.test.js @@ -0,0 +1,51 @@ +/* eslint-disable no-console */ + +// this basic server health check is meant to be run before integration tests +// it should be run with the same environment variables as the integration tests +// and operate in the same way as the integration tests + +const SeleniumHelper = require('../integration/selenium-helpers.js'); + +const rootUrl = process.env.ROOT_URL || (() => { + const ROOT_URL_DEFAULT = 'https://scratch.ly'; + console.warn(`ROOT_URL not set, defaulting to ${ROOT_URL_DEFAULT}`); + return ROOT_URL_DEFAULT; +})(); + +jest.setTimeout(60000); + +describe('www server health check', () => { + /** @type {import('selenium-webdriver').ThenableWebDriver} */ + let driver; + + /** @type {SeleniumHelper} */ + let seleniumHelper; + + beforeAll(() => { + seleniumHelper = new SeleniumHelper(); + driver = seleniumHelper.buildDriver('www server health check'); + }); + + afterAll(() => driver.quit()); + + test('server is healthy', async () => { + const healthUrl = new URL('health/', rootUrl); + await driver.get(healthUrl.toString()); + + // Note: driver.getPageSource() will return the pretty HTML form of the JSON + const pageText = await driver.executeScript('return document.body.innerText'); + + let healthObject; + let serverReturnedValidJson = false; + + try { + healthObject = JSON.parse(pageText); + serverReturnedValidJson = true; + } catch (_e) { + // ignore + } + + expect(serverReturnedValidJson).toBe(true); + expect(healthObject).toHaveProperty('healthy', true); + }); +});