Skip to content

Commit

Permalink
Merge pull request #2058 from BetterThanTomorrow/pez/e2e-tests-config…
Browse files Browse the repository at this point in the history
…urability

Make e2e test runner re-usable
  • Loading branch information
PEZ authored Feb 2, 2023
2 parents 89c1f5f + dd8f7d6 commit 751576c
Show file tree
Hide file tree
Showing 34 changed files with 127 additions and 7,979 deletions.
43 changes: 37 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ jobs:
command: npm run integration-test
- store_test_results:
path: ~/calva/junit
test-vsix:
test-e2e:
docker:
- image: cimg/clojure:1.11-browsers
working_directory: ~/calva
Expand All @@ -233,7 +233,25 @@ jobs:
command: sudo apt update && sudo apt install -y libnss3
- run:
name: Run VSIX E2E Tests
command: npm run vsix-test /tmp/artifacts/calva-$(node -p 'require("./package.json").version').vsix
command: npm run e2e-test -- --calva-vsix=/tmp/artifacts/calva-$(node -p 'require("./package.json").version').vsix --test-workspace=src/extension-test/e2e-test
- store_test_results:
path: ~/calva/junit
test-e2e-sub-projects:
docker:
- image: cimg/clojure:1.11-browsers
working_directory: ~/calva
steps:
- attach_workspace:
at: /tmp
- run:
name: Restore build
command: rmdir ~/calva && cp -r /tmp/build ~/calva
- run:
name: Apt install missing dependencies
command: sudo apt update && sudo apt install -y libnss3
- run:
name: Run VSIX E2E Tests for test-data/projects/e2e-sub-projects
command: npm run e2e-test -- --calva-vsix=/tmp/artifacts/calva-$(node -p 'require("./package.json").version').vsix --test-workspace=test-data/projects/e2e-sub-projects
- store_test_results:
path: ~/calva/junit
github-release:
Expand Down Expand Up @@ -446,7 +464,10 @@ workflows:
- test-integration:
requires:
- build
- test-vsix:
- test-e2e:
requires:
- build
- test-e2e-sub-projects:
requires:
- build
- test-ts-unit:
Expand All @@ -459,7 +480,8 @@ workflows:
- test-grammar
- test-cljslib
- test-integration
- test-vsix
- test-e2e
- test-e2e-sub-projects
- test-ts-unit
filters:
branches:
Expand Down Expand Up @@ -521,7 +543,15 @@ workflows:
ignore: /.*/
tags:
only: /^v\d+\.\d+\.\d+-?.*/
- test-vsix:
- test-e2e:
requires:
- build
filters:
branches:
ignore: /.*/
tags:
only: /^v\d+\.\d+\.\d+-?.*/
- test-e2e-sub-projects:
requires:
- build
filters:
Expand All @@ -544,7 +574,8 @@ workflows:
- test-grammar
- test-cljslib
- test-integration
- test-vsix
- test-e2e
- test-e2e-sub-projects
- test-ts-unit
filters:
branches:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changes to Calva.

## [Unreleased]

- [Make e2e test runner re-usable](https://github.com/BetterThanTomorrow/calva/issues/2058)

## [2.0.329] - 2023-02-01

- [Sort aliases for deps.edn projects](https://github.com/BetterThanTomorrow/calva/issues/2035)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2889,7 +2889,8 @@
"bump-version": "npm set git-tag-version false && npm version patch",
"calva-lib-test": "node ./out/cljs-lib/test/cljs-lib-tests.js",
"integration-test": "node ./out/extension-test/integration/runTests.js",
"vsix-test": "node ./vsix-test/launch.js",
"e2e-test": "node ./src/extension-test/e2e-test/launch.js",
"pree2e-test": "cd ./src/extension-test/e2e-test/ && npm i",
"unit-test": "npx mocha --require ts-node/register 'src/extension-test/unit/**/*-test.ts'",
"unit-test-watch": "npx mocha --watch --require ts-node/register --watch-extensions ts --watch-files src 'src/extension-test/unit/**/*-test.ts'",
"prettier-format": "npx prettier --write \"./**/*.{ts,js,json}\"",
Expand Down
4 changes: 4 additions & 0 deletions src/extension-test/e2e-test/.joyride/src/config.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(ns config)

(defn ns-symbols []
['tests.a-test])
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns test-runner
(:require [clojure.string :as string]
[cljs.test]
[config :as config]
[db :as db]
[promesa.core :as p]))

Expand All @@ -16,7 +17,7 @@
(def old-pass (get-method cljs.test/report [:cljs.test/default :pass]))

(defmethod cljs.test/report [:cljs.test/default :pass] [m]
(binding [*print-fn* write] (old-pass m))
(binding [*print-fn* write] (old-pass m))
(write "")
(swap! db/!state update :pass inc))

Expand Down Expand Up @@ -55,16 +56,19 @@
(if (:ws-activated? @db/!state)
(do
(println "Runner: Workspace activated, running tests...")
(require '[tests.a-test])
(cljs.test/run-tests 'tests.a-test))
(try
(doseq [ns-sym (config/ns-symbols)]
(require ns-sym)
(cljs.test/run-tests ns-sym))
(catch :default e
(p/reject! (:running @db/!state) e))))
(do
(println "Runner: Workspace not activated yet, tries: " tries "- trying again in a jiffy")
(js/setTimeout #(run-when-ws-activated (inc tries)) 10))))

(defn run-all-tests []
(let [running (p/deferred)]
(swap! db/!state assoc
:running running)
(swap! db/!state assoc :running running)
(run-when-ws-activated 1)
running))

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 19 additions & 16 deletions vsix-test/launch.js → src/extension-test/e2e-test/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,41 +29,43 @@ function init() {
});
}

async function main(calvaVSIXPath) {
async function main(calvaVSIXPathOrLabel, testWorkspace) {
try {
const extensionTestsPath = path.resolve(__dirname, 'runTests');
const vscodeExecutablePath = await downloadAndUnzipVSCode('insiders');
const cliPath = resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath);
const testWorkspace = path.resolve(__dirname);

const launchArgs = [
testWorkspace,
'--disable-workspace-trust',
'--install-extension',
// TODO: Build the extension first, and use the built version here
// In CI we will have built the extension already, so it is
// more a TODO to figure out where to find the built extension
calvaVSIXPath,
// WHen debugging tests, it can be good to use the development version of Joyride
// When debugging tests, it can be good to use the development version of Joyride
// If you do, comment out the install of the Joyride extension here
// And set the `extensionDevelopmentPath` in the `runTests` call below
// (And can't be used if you are testing the development version of Calva)
'--install-extension',
'betterthantomorrow.joyride',
];
if (calvaVSIXPathOrLabel !== 'extension-development') {
launchArgs.push('--install-extension', calvaVSIXPathOrLabel);
}

cp.spawnSync(cliPath, launchArgs, {
encoding: 'utf-8',
stdio: 'inherit',
});

await runTests({
const runOptions = {
// When debugging tests, it can be good to use the development version Joyride
// extensionDevelopmentPath: '/Users/pez/Projects/joyride',
vscodeExecutablePath,
reuseMachineInstall: true,
extensionTestsPath,
launchArgs: [testWorkspace],
})
};
if (calvaVSIXPathOrLabel === 'extension-development') {
runOptions.extensionDevelopmentPath = path.resolve(__dirname, '..');
}
await runTests(runOptions)
.then((_result) => {
console.info('Tests finished');
})
Expand All @@ -77,14 +79,15 @@ async function main(calvaVSIXPath) {
}
}

const calvaVSIXPath = process.argv[2];
if (!calvaVSIXPath) {
console.error('Missing path to Calva VSIX file');
process.exit(1);
}
const args = require('minimist')(process.argv.slice(2));
const calvaVSIX = args['calva-vsix'] ? args['calva-vsix'] : 'extension-development';
const testWorkspace = args['test-workspace']
? path.resolve(args['test-workspace'])
: path.resolve(__dirname);
console.info(`Using:\n Calva: ${calvaVSIX}\n Test workspace: ${testWorkspace}`);

void init()
.then(() => main(calvaVSIXPath))
.then(() => main(calvaVSIX, testWorkspace))
.catch((error) => {
console.error('Failed to initialize test running environment:', error);
process.exit(1);
Expand Down
24 changes: 24 additions & 0 deletions src/extension-test/e2e-test/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
"email": "pez@pezius.com"
},
"license": "MIT",
"dependencies": {}
"dependencies": {
"minimist": "^1.2.7"
}
}
File renamed without changes.
4 changes: 4 additions & 0 deletions test-data/projects/e2e-sub-projects/.joyride/src/config.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(ns config)

(defn ns-symbols []
['tests.example-test])
1 change: 1 addition & 0 deletions test-data/projects/e2e-sub-projects/.joyride/src/db.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(ns tests.example-test
(:require [cljs.test :refer [deftest testing is]]
[promesa.core :as p]
[macros :refer [deftest-async]]))

(deftest a-sync-test
(testing "A sync test"
(is (not= nil? 1))))

(deftest-async an-async-test
(testing "Requires the Joyride extension"
(p/let [answer (p/resolved 42)]
(is (= 42 answer)))))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(ns a)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(ns b)
1 change: 1 addition & 0 deletions test-data/projects/e2e-sub-projects/project-a/a.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(ns a)
1 change: 1 addition & 0 deletions test-data/projects/e2e-sub-projects/project-a/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:paths ["."]}
1 change: 1 addition & 0 deletions test-data/projects/e2e-sub-projects/project-b/b.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(ns b)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Loading

0 comments on commit 751576c

Please sign in to comment.