# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
---
newtab-unit-tests:
    description: newtab unit tests
    platform: linux1804-64/opt
    treeherder:
        symbol: node(newtab)
        kind: test
        tier: 1
    worker-type: t-linux-xlarge-source
    worker:
        docker-image: {in-tree: "ubuntu1804-test"}
        max-run-time: 1800
    require-build:
        by-project:
            autoland:
                linux1804-64/opt: build-linux64/opt
            try:
                linux1804-64/opt: build-linux64/opt
            default:
                linux1804-64/opt: build-linux64-shippable/opt
    run:
        using: run-task
        cache-dotcache: true
        cwd: '{checkout}'
        command: >
            cd /builds/worker/checkouts/gecko &&
            rm -rf node_modules &&
            npm ci &&
            cd /builds/worker/checkouts/gecko/browser/components/aboutwelcome &&
            rm -rf node_modules &&
            npm ci &&
            cd /builds/worker/checkouts/gecko/browser/components/asrouter &&
            rm -rf node_modules &&
            npm ci &&
            cd /builds/worker/checkouts/gecko/browser/components/newtab &&
            rm -rf node_modules &&
            npm ci &&
            node bin/try-runner.js
    when:
        files-changed:
            - "browser/components/newtab/**"
            - "browser/components/aboutwelcome/**"
            - "browser/components/asrouter/**"

newtab-unit-tests-ccov:
    description: newtab unit tests code coverage
    platform: linux1804-64/opt
    treeherder:
        symbol: node(newtab-ccov)
        kind: test
        tier: 1
    worker-type: t-linux-xlarge-source
    worker:
        docker-image: {in-tree: "ubuntu1804-test"}
        max-run-time: 1800
        artifacts:
            - name: public/code-coverage-grcov.zip
              path: /builds/worker/checkouts/gecko/browser/components/newtab/logs/coverage/code-coverage-grcov.zip
              type: file
    require-build:
        by-project:
            try:
                linux1804-64/opt: build-linux64/opt
            default:
                linux1804-64/opt: build-linux64-shippable/opt
    run:
        using: run-task
        cache-dotcache: true
        cwd: '{checkout}'
        command: >
            cd /builds/worker/checkouts/gecko &&
            rm -rf node_modules &&
            npm ci &&
            cd /builds/worker/checkouts/gecko/browser/components/aboutwelcome &&
            rm -rf node_modules &&
            npm ci &&
            cd /builds/worker/checkouts/gecko/browser/components/asrouter &&
            rm -rf node_modules &&
            npm ci &&
            cd /builds/worker/checkouts/gecko/browser/components/newtab &&
            rm -rf node_modules &&
            npm ci &&
            node bin/try-runner.js
    # This should only run on mozilla-central, as the bot will only parse mozilla-central
    # coverage anyways.
    run-on-projects: ["mozilla-central"]
    # Note the lack of a "when" rule here. This is to avoid seeing fluctuating
    # coverage on coverage.moz.tools / searchfox depending on whether the latest
    # push contained patches touching these files or not.

devtools-tests:
    description: devtools node-based tests (for instance jest)
    platform: linux1804-64/opt
    attributes:
        code-review: true
    treeherder:
        symbol: node(devtools)
        kind: test
        tier: 1
    worker-type: t-linux-xlarge-source
    worker:
        docker-image: {in-tree: "lint"}
        max-run-time: 1800
        artifacts:
            - type: file
              name: public/code-review/issues.json
              path: /builds/worker/issues.json
    run:
        using: run-task
        cache-dotcache: true
        cwd: '{checkout}'
        # Re-use rather than re-installing to avoid hitting/requiring
        # nodejs servers for downloads
        command: >
            cp -r /build/node_modules_eslint node_modules &&
            cp -r /build/node_modules_eslint-plugin-mozilla/ tools/lint/eslint/eslint-plugin-mozilla/node_modules &&
            ln -s ../tools/lint/eslint/eslint-plugin-mozilla node_modules &&
            ln -s ../tools/lint/eslint/eslint-plugin-spidermonkey-js node_modules &&
            cd devtools/client/bin/ &&
            node devtools-node-test-runner.js --suite=all --artifact=/builds/worker/issues.json
    when:
        files-changed:
            - 'devtools/client/**'
            - 'devtools/shared/**'

devtools-verify-bundle:
    description: devtools bundle checker
    platform: linux1804-64/opt
    attributes:
        code-review: true
    treeherder:
        symbol: node(devtools-bundle)
        kind: test
        tier: 2
    worker-type: t-linux-xlarge-source
    worker:
        docker-image: {in-tree: "lint"}
        max-run-time: 1200
        artifacts:
            - type: file
              name: public/code-review/issues.json
              path: /builds/worker/issues.json
    run:
        using: run-task
        cache-dotcache: true
        cwd: '{checkout}'
        # Re-use rather than re-installing to avoid hitting/requiring
        # nodejs servers for downloads
        command: >
            cp -r /build/node_modules_eslint node_modules &&
            cp -r /build/node_modules_eslint-plugin-mozilla/ tools/lint/eslint/eslint-plugin-mozilla/node_modules &&
            ln -s ../tools/lint/eslint/eslint-plugin-mozilla node_modules &&
            ln -s ../tools/lint/eslint/eslint-plugin-spidermonkey-js node_modules &&
            cd devtools/client/debugger &&
            yarn &&
            node bin/bundle.js &&
            cd ../../.. &&
            ./mach python taskcluster/scripts/misc/verify-devtools-bundle.py --output /builds/worker/issues.json
    when:
        files-changed:
            - 'devtools/**'

eslint-plugin-mozilla:
    description: eslint-plugin-mozilla integration tests
    platform: linux1804-64/opt
    treeherder:
        symbol: node(epm)
        kind: test
        tier: 1
    worker-type: t-linux-xlarge-source
    worker:
        docker-image: {in-tree: "lint"}
        max-run-time: 1800
    run:
        using: run-task
        cache-dotcache: true
        cwd: '{checkout}/tools/lint/eslint/eslint-plugin-mozilla'
        command: >
            cp -r /build/node_modules_eslint-plugin-mozilla node_modules &&
            npm run test
    when:
        files-changed:
            - 'tools/lint/eslint/eslint-plugin-mozilla/**'

design-tokens-tests:
    description: design tokens unit tests
    platform: linux1804-64/opt
    treeherder:
        symbol: node(design-tokens)
        kind: test
        tier: 1
    worker-type: t-linux-xlarge-source
    worker:
        docker-image: {in-tree: "ubuntu1804-test"}
        max-run-time: 1800
    require-build:
        by-project:
            autoland:
                linux1804-64/opt: build-linux64/opt
            try:
                linux1804-64/opt: build-linux64/opt
            default:
                linux1804-64/opt: build-linux64-shippable/opt
    run:
        using: run-task
        cache-dotcache: true
        cwd: '{checkout}'
        command: >
            cd /builds/worker/checkouts/gecko &&
            rm -rf node_modules &&
            npm ci &&
            cd /builds/worker/checkouts/gecko/toolkit/themes/shared/design-system &&
            rm -rf node_modules &&
            npm ci &&
            node tests/try-runner.js
    when:
        files-changed:
            - "toolkit/themes/shared/design-system/**"
