@author lanceball
| 18 | * @author lanceball |
| 19 | */ |
| 20 | public class TestRunner { |
| 21 | |
| 22 | private static final String SCRIPT = "" + |
| 23 | "var executor = require('./target/test-classes/specRunner.js');" + |
| 24 | "executor.run('" + testPattern() + "');"; |
| 25 | |
| 26 | public static String testPattern() { |
| 27 | String pattern = System.getProperty("test.pattern"); |
| 28 | if (pattern == null) { |
| 29 | pattern = "**/*Spec.js"; |
| 30 | } |
| 31 | |
| 32 | return pattern; |
| 33 | } |
| 34 | |
| 35 | public static void main(String... args) throws InterruptedException { |
| 36 | TestRunner runner = new TestRunner(); |
| 37 | runner.run(); |
| 38 | } |
| 39 | |
| 40 | private final ScheduledExecutorService executor; |
| 41 | private final List<Future> futures = new ArrayList<>(); |
| 42 | private final AtomicInteger counter = new AtomicInteger(0); |
| 43 | private final CountDownLatch finishLatch = new CountDownLatch(1); |
| 44 | private final DynJS dynjs; |
| 45 | |
| 46 | public TestRunner() { |
| 47 | Config config = new Config(TestRunner.class.getClassLoader()); |
| 48 | config.setCompileMode(Config.CompileMode.OFF); |
| 49 | this.executor = Executors.newSingleThreadScheduledExecutor( new ThreadFactory() { |
| 50 | @Override |
| 51 | public Thread newThread(Runnable r) { |
| 52 | Thread t = new Thread(r); |
| 53 | t.setDaemon(false); |
| 54 | return t; |
| 55 | } |
| 56 | }); |
| 57 | //config.setArgv(new String[]{ SCRIPT}); |
| 58 | this.dynjs = new DynJS(config); |
| 59 | setupTimers(); |
| 60 | setupConsole(); |
| 61 | } |
| 62 | |
| 63 | public void increment() { |
| 64 | counter.incrementAndGet(); |
| 65 | } |
| 66 | |
| 67 | public void decrement() { |
| 68 | int val = counter.decrementAndGet(); |
| 69 | if ( val == 0 ) { |
| 70 | finishLatch.countDown(); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | public void run() throws InterruptedException { |
| 75 | counter.incrementAndGet(); |
| 76 | futures.add(executor.submit(new Runnable() { |
| 77 | @Override |
nothing calls this directly
no test coverage detected