diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000000..318d0a67a18 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,108 @@ +version: 2.0 + +# Inspired by: +# https://github.com/CircleCI-Public/circleci-demo-workflows/blob/workspace-forwarding/.circleci/config.yml +# https://circleci.com/docs/2.0/workflows/#using-workspaces-to-share-data-among-jobs + +jobs: + build: + docker: + - image: circleci/node:6.10.3 + working_directory: ~/plotly.js + steps: + - checkout + - restore_cache: + keys: + - v{{ .Environment.CIRCLE_CACHE_VERSION }}-deps-{{ .Branch }}-{{ checksum "package.json" }} + - v{{ .Environment.CIRCLE_CACHE_VERSION }}-deps-master-{{ checksum "package.json" }} + - run: + name: Install dependencies + command: | + npm install + npm dedupe + npm prune + npm install + - run: + name: List dependency versions + command: | + echo "npm: $(npm --version)" + echo "node: $(node --version)" + npm ls || true + - run: + name: Pretest + command: | + npm run pretest + npm run cibuild + - save_cache: + paths: + - node_modules + key: v{{ .Environment.CIRCLE_CACHE_VERSION }}-deps-{{ .Branch }}-{{ checksum "package.json" }} + - persist_to_workspace: + root: . + paths: + - node_modules + - build + - dist + + test-jasmine: + docker: + # need '-browsers' version to test in real (xvfb-wrapped) browsers + - image: circleci/node:6.10.3-browsers + working_directory: ~/plotly.js + steps: + - checkout + - attach_workspace: + at: ~/plotly.js + - run: + name: Set timezone to Alaska time (arbitrary timezone to test date logic) + command: | + sudo cp /usr/share/zoneinfo/America/Anchorage /etc/localtime + - run: + name: Run jasmine tests + command: ./.circleci/test.sh jasmine + + test-image: + docker: + - image: plotly/testbed:latest + working_directory: /var/www/streambed/image_server/plotly.js/ + steps: + - checkout + - attach_workspace: + at: /var/www/streambed/image_server/plotly.js/ + - run: + name: Run and setup container + command: | + supervisord & + npm run docker -- setup + - run: + name: Run image tests + command: ./.circleci/test.sh image + - store_artifacts: + path: build + + test-syntax: + docker: + - image: circleci/node:6.10.3 + working_directory: ~/plotly.js + steps: + - checkout + - attach_workspace: + at: ~/plotly.js + - run: + name: Run syntax tests + command: ./.circleci/test.sh syntax + +workflows: + version: 2 + build-and-test: + jobs: + - build + - test-jasmine: + requires: + - build + - test-image: + requires: + - build + - test-syntax: + requires: + - build diff --git a/tasks/ci_test.sh b/.circleci/test.sh similarity index 50% rename from tasks/ci_test.sh rename to .circleci/test.sh index de7ddd51719..a1bcd5e1bf5 100755 --- a/tasks/ci_test.sh +++ b/.circleci/test.sh @@ -1,21 +1,29 @@ #!/bin/bash +# override CircleCi's default run settings +set +e +set +o pipefail + EXIT_STATE=0 -case $CIRCLE_NODE_INDEX in +case $1 in + + jasmine) + npm run test-jasmine || EXIT_STATE=$? + npm run test-bundle || EXIT_STATE=$? + exit $EXIT_STATE + ;; - 0) + image) npm run test-image || EXIT_STATE=$? + npm run test-export || EXIT_STATE=$? npm run test-image-gl2d || EXIT_STATE=$? - npm run test-bundle || EXIT_STATE=$? - npm run lint || EXIT_STATE=$? exit $EXIT_STATE ;; - 1) - npm run test-jasmine || EXIT_STATE=$? - npm run test-export || EXIT_STATE=$? - npm run test-syntax || EXIT_STATE=$? + syntax) + npm run lint || EXIT_STATE=$? + npm run test-syntax || EXIT_STATE=$? exit $EXIT_STATE ;; diff --git a/.gitignore b/.gitignore index 950f16c4ee1..dc4448c5c8e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ npm-debug.log* *.sublime* .* +!.circleci !.gitignore !.npmignore !.eslintrc diff --git a/circle.yml b/circle.yml deleted file mode 100644 index 285ebd40ea8..00000000000 --- a/circle.yml +++ /dev/null @@ -1,27 +0,0 @@ -general: - artifacts: - - build/test_images/ - - build/test_images_diff/ - -machine: - node: - version: 6.1.0 - timezone: - America/Anchorage - services: - - docker - -dependencies: - override: - - npm install && npm dedupe && npm prune && npm install - - npm ls || true - - npm run docker -- pull - - npm run pretest - - npm run docker -- run - - npm run cibuild - - npm run docker -- setup - -test: - override: - - ./tasks/ci_test.sh: - parallel: true diff --git a/package.json b/package.json index 5f6b9d8e5a2..adcb3d1b5c6 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "start-image_viewer": "node devtools/image_viewer/server.js", "start": "npm run start-test_dashboard", "baseline": "node tasks/baseline.js", - "preversion": "npm-link-check && npm dedupe", + "preversion": "npm-link-check && npm dedupe && npm ls --prod", "version": "npm run build && git add -A dist src build", "postversion": "node -e \"console.log('Version bumped and committed. If ok, run: git push && git push --tags')\"" }, diff --git a/tasks/noci_test.sh b/tasks/noci_test.sh index 17d7dfc4c50..c92ea7dd62c 100755 --- a/tasks/noci_test.sh +++ b/tasks/noci_test.sh @@ -10,7 +10,4 @@ npm run test-jasmine -- --tags=noCI --nowatch || EXIT_STATE=$? # mapbox image tests take too much resources on CI npm run test-image -- mapbox_* --queue || EXIT_STATE=$? -# run gl2d image test again (some mocks are skipped on CI) -npm run test-image-gl2d || EXIT_STATE=$? - exit $EXIT_STATE diff --git a/tasks/util/container_commands.js b/tasks/util/container_commands.js index b4f1f3e3429..fa011c5eaf2 100644 --- a/tasks/util/container_commands.js +++ b/tasks/util/container_commands.js @@ -44,31 +44,17 @@ containerCommands.getRunCmd = function(isCI, commands) { function getRunLocal(commands) { commands = [containerCommands.cdHome].concat(commands); - - var commandsJoined = '"' + commands.join(' && ') + '"'; - return [ 'docker exec -i', constants.testContainerName, '/bin/bash -c', - commandsJoined + '"' + commands.join(' && ') + '"' ].join(' '); } function getRunCI(commands) { - commands = ['export CIRCLECI=1', containerCommands.cdHome].concat(commands); - - var commandsJoined = '"' + commands.join(' && ') + '"'; - var containerId = '$(docker inspect --format \'{{.Id}}\' ' + constants.testContainerName + ')'; - - return [ - 'sudo', - 'lxc-attach', - '-n', containerId, - '-f', '/var/lib/docker/containers/' + containerId + '/config.lxc', - '-- bash -c', - commandsJoined - ].join(' '); + commands = [containerCommands.cdHome].concat(commands); + return commands.join(' && '); } module.exports = containerCommands; diff --git a/test/jasmine/tests/toimage_test.js b/test/jasmine/tests/toimage_test.js index f419504d03d..3f1181a4c26 100644 --- a/test/jasmine/tests/toimage_test.js +++ b/test/jasmine/tests/toimage_test.js @@ -149,7 +149,7 @@ describe('Plotly.toImage', function() { .then(function() { return Plotly.toImage(gd, {format: 'png', imageDataOnly: true}); }) .then(function(d) { expect(d.indexOf('data:image/')).toBe(-1); - expect(d.length).toBeWithin(54660, 3e3, 'png image length'); + expect(d.length).toBeWithin(50000, 5e3, 'png image length'); }) .then(function() { return Plotly.toImage(gd, {format: 'jpeg', imageDataOnly: true}); }) .then(function(d) {