Skip to content

Commit

Permalink
Add support to monorepos (#513)
Browse files Browse the repository at this point in the history
* Mono repos support

* use bash to run system tests

* Remove comment
  • Loading branch information
f-moya authored Feb 23, 2021
1 parent ca57545 commit a1878e1
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 5 deletions.
15 changes: 11 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: image test citest integration yarn.lock yarn.add
.PHONY: image test test.unit test.integration test.system citest.base citest integration yarn.lock yarn.add

IMAGE_NAME ?= codeclimate/codeclimate-eslint

Expand All @@ -14,29 +14,36 @@ endif
image:
docker build --rm -t $(IMAGE_NAME) .

integration: yarn.lock
test.integration: yarn.lock
docker run -ti --rm \
-v $(PWD):/usr/src/app \
--workdir /usr/src/app \
$(IMAGE_NAME) npm run $(NPM_INTEGRATION_TARGET)

test: yarn.lock
test.unit:
docker run -ti --rm \
-v $(PWD):/usr/src/app \
--workdir /usr/src/app \
$(IMAGE_NAME) npm run $(NPM_TEST_TARGET)

test.system:
bash run-system-tests.sh

test: yarn.lock test.unit test.integration test.system

yarn.add:
docker run -ti --rm \
-v $(PWD):/usr/src/app \
--workdir /usr/src/app \
$(IMAGE_NAME) yarn add $(ARGS)

citest:
citest.base:
docker run --rm \
--workdir /usr/src/app \
$(IMAGE_NAME) sh -c "npm run test && npm run integration"

citest: citest.base test.system

yarn.lock: package.json Dockerfile
$(MAKE) image
./bin/yarn install
Expand Down
2 changes: 1 addition & 1 deletion lib/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const checks = require("./checks")
const computeFingerprint = require("./compute_fingerprint")

const CLIEngine = patch.eslint.CLIEngine
const options = { extensions: [".js"], ignore: true, reset: false, useEslintrc: true }
const options = { extensions: [".js"], ignore: true, reset: false, useEslintrc: true, baseConfig: {} }

function run(console, runOptions) {
const STDOUT = console.log
Expand Down
40 changes: 40 additions & 0 deletions run-system-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

echo "▶ Running system tests..."

if [[ "$(docker images -q codeclimate/codeclimate-eslint 2> /dev/null)" == "" ]]; then
echo "▶ Building image..."
make image
fi

SOURCE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

for d in system-tests/*/ ; do
echo ""
echo "▶ Running $d ..."
echo "${SOURCE}"/"${d}"
cd "${SOURCE}"/"${d}" || exit
output=$(docker run \
--interactive --tty --rm \
--env CODECLIMATE_CODE="$PWD" \
--volume "$PWD":/code \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume /tmp/cc:/tmp/cc \
codeclimate/codeclimate analyze --dev)

if [[ -f "${SOURCE}/${d}snapshot" ]]; then
count=$(cat "${SOURCE}"/"${d}"snapshot)
issues=$(echo ${output} | sed -E "s/.*Found ([0-9]+).*/\1/")

if [[ "$issues" -ne "$count" ]]; then
echo -e "FAIL It should have $count issues but found $issues";
exit 1
else
echo -e "PASS Found $issues issues"
fi
fi

if [[ "$?" -ne 0 ]]; then
break
fi
done
4 changes: 4 additions & 0 deletions system-tests/mono-repo/.codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: "2"
plugins:
eslint:
enabled: true
7 changes: 7 additions & 0 deletions system-tests/mono-repo/code-a/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: ['./eslint-config-frontier-react.js'],
plugins: ['prettier'],
ignorePatterns: [
"fle-b.js"
],
};
9 changes: 9 additions & 0 deletions system-tests/mono-repo/code-a/file-a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
let a;
const foo = function () {
console.log('hey')
}

console.log('hello')
console.log('world')

foo()
3 changes: 3 additions & 0 deletions system-tests/mono-repo/code-a/file-b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let b;
console.log("helper");
console.log("world");
5 changes: 5 additions & 0 deletions system-tests/mono-repo/code-b/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
ignorePatterns: [
"file-a.js"
],
};
3 changes: 3 additions & 0 deletions system-tests/mono-repo/code-b/file-a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let d;
console.log("helper");
console.log("world");
9 changes: 9 additions & 0 deletions system-tests/mono-repo/code-b/file-b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
let c;
const foo = function () {
console.log('hey')
}

console.log('hello')
console.log('world')

foo()
1 change: 1 addition & 0 deletions system-tests/mono-repo/snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
4 changes: 4 additions & 0 deletions system-tests/no-config/.codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: "2"
plugins:
eslint:
enabled: true
9 changes: 9 additions & 0 deletions system-tests/no-config/file-a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
let a;
const foo = function () {
console.log('hey')
}

console.log('hello')
console.log('world')

foo()
3 changes: 3 additions & 0 deletions system-tests/no-config/file-b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let b;
console.log("helper");
console.log("world");
1 change: 1 addition & 0 deletions system-tests/no-config/snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2

0 comments on commit a1878e1

Please sign in to comment.