|
1 |
| -# |
2 |
| -# Binaries. |
3 |
| -# |
4 |
| - |
5 |
| -DUO = node_modules/.bin/duo |
6 |
| -DUOT = node_modules/.bin/duo-test |
7 |
| -ESLINT = node_modules/.bin/eslint |
8 |
| - |
9 |
| -# |
10 |
| -# Files. |
11 |
| -# |
12 |
| - |
13 |
| -SRCS_DIR = lib |
14 |
| -SRCS = $(shell find $(SRCS_DIR) -type f -name "*.js") |
15 |
| -TESTS_DIR = test |
16 |
| -TESTS = $(shell find $(TESTS_DIR) -type f -name '*.test.js') |
17 |
| - |
18 |
| -# |
19 |
| -# Task config. |
20 |
| -# |
21 |
| - |
22 |
| -BROWSER ?= chrome |
23 |
| - |
24 |
| -PORT ?= 0 |
25 |
| - |
26 |
| -DUOT_ARGS = \ |
27 |
| - --reporter spec \ |
28 |
| - --port $(PORT) \ |
29 |
| - --commands "make build" |
30 |
| - |
31 |
| -# |
32 |
| -# Chore tasks. |
33 |
| -# |
34 |
| - |
35 |
| -# Install node dependencies. |
| 1 | +## |
| 2 | +# Binaries |
| 3 | +## |
| 4 | + |
| 5 | +ESLINT := node_modules/.bin/eslint |
| 6 | +KARMA := node_modules/.bin/karma |
| 7 | + |
| 8 | +## |
| 9 | +# Files |
| 10 | +## |
| 11 | + |
| 12 | +LIBS = $(shell find lib -type f -name "*.js") |
| 13 | +TESTS = $(shell find test -type f -name "*.test.js") |
| 14 | +SUPPORT = $(wildcard karma.conf*.js) |
| 15 | +ALL_FILES = $(LIBS) $(TESTS) $(SUPPORT) |
| 16 | + |
| 17 | +## |
| 18 | +# Program options/flags |
| 19 | +## |
| 20 | + |
| 21 | +# A list of options to pass to Karma |
| 22 | +# Overriding this overwrites all options specified in this file (e.g. BROWSERS) |
| 23 | +KARMA_FLAGS ?= |
| 24 | + |
| 25 | +# A list of Karma browser launchers to run |
| 26 | +# http://karma-runner.github.io/0.13/config/browsers.html |
| 27 | +BROWSERS ?= |
| 28 | +ifdef BROWSERS |
| 29 | +KARMA_FLAGS += --browsers $(BROWSERS) |
| 30 | +endif |
| 31 | + |
| 32 | +ifdef CI |
| 33 | +KARMA_CONF ?= karma.conf.ci.js |
| 34 | +else |
| 35 | +KARMA_CONF ?= karma.conf.js |
| 36 | +endif |
| 37 | + |
| 38 | +# Mocha flags. |
| 39 | +GREP ?= . |
| 40 | + |
| 41 | +## |
| 42 | +# Tasks |
| 43 | +## |
| 44 | + |
| 45 | +# Install node modules. |
36 | 46 | node_modules: package.json $(wildcard node_modules/*/package.json)
|
37 | 47 | @npm install
|
| 48 | + @touch $@ |
| 49 | + |
| 50 | +# Install dependencies. |
| 51 | +install: node_modules |
38 | 52 |
|
39 | 53 | # Remove temporary files and build artifacts.
|
40 | 54 | clean:
|
41 |
| - rm -rf build.js |
| 55 | + rm -rf *.log coverage |
42 | 56 | .PHONY: clean
|
43 | 57 |
|
44 | 58 | # Remove temporary files, build artifacts, and vendor dependencies.
|
45 | 59 | distclean: clean
|
46 |
| - rm -rf components node_modules |
| 60 | + rm -rf node_modules |
47 | 61 | .PHONY: distclean
|
48 | 62 |
|
49 |
| -# |
50 |
| -# Build tasks. |
51 |
| -# |
52 |
| - |
53 |
| -# Build all integrations, tests, and dependencies together for testing. |
54 |
| -build.js: node_modules component.json $(SRCS) $(TESTS) |
55 |
| - @$(DUO) --stdout --development $(TESTS) > $@ |
56 |
| - |
57 |
| -# Build shortcut. |
58 |
| -build: build.js |
59 |
| -.DEFAULT_GOAL = build |
| 63 | +# Lint JavaScript source files. |
| 64 | +lint: install |
| 65 | + @$(ESLINT) $(ALL_FILES) |
| 66 | +.PHONY: lint |
60 | 67 |
|
61 |
| -# |
62 |
| -# Test tasks. |
63 |
| -# |
| 68 | +# Attempt to fix linting errors. |
| 69 | +fmt: install |
| 70 | + @$(ESLINT) --fix $(ALL_FILES) |
| 71 | +.PHONY: fmt |
64 | 72 |
|
65 |
| -# Lint JavaScript source. |
66 |
| -lint: node_modules |
67 |
| - @$(ESLINT) $(SRCS) $(TESTS) |
68 |
| -.PHONY: lint |
| 73 | +# Run browser unit tests in a browser. |
| 74 | +test-browser: install |
| 75 | + @$(KARMA) start $(KARMA_FLAGS) $(KARMA_CONF) |
69 | 76 |
|
70 |
| -# Test locally in PhantomJS. |
71 |
| -test-phantomjs: node_modules build.js |
72 |
| - @$(DUOT) phantomjs $(TESTS_DIR) args: \ |
73 |
| - --ignore-ssl-errors=true --ssl-protocol=tlsv1 --path node_modules/.bin/phantomjs |
74 |
| -.PHONY: test-phantomjs |
75 |
| - |
76 |
| -# Test locally in the browser. |
77 |
| -test-browser: node_modules build.js |
78 |
| - @$(DUOT) browser --commands "make build" $(TESTS_DIR) |
79 |
| -.PHONY: test-browser |
80 |
| - |
81 |
| -# Test in Sauce Labs. Note that you must set the SAUCE_USERNAME and |
82 |
| -# SAUCE_ACCESS_KEY environment variables using your Sauce Labs credentials. |
83 |
| -test-sauce: node_modules build.js |
84 |
| - @$(DUOT) saucelabs $(TESTS_DIR) \ |
85 |
| - --name analytics.js-integrations \ |
86 |
| - --browsers $(BROWSER) \ |
87 |
| - --user $(SAUCE_USERNAME) \ |
88 |
| - --key $(SAUCE_ACCESS_KEY) |
89 |
| -.PHONY: test-sauce |
90 |
| - |
91 |
| -# Test shortcut. |
92 |
| -test: lint test-phantomjs |
| 77 | +# Default test target. |
| 78 | +test: lint test-browser |
93 | 79 | .PHONY: test
|
| 80 | +.DEFAULT_GOAL = test |
0 commit comments