|
1 | 1 | import assert from 'assert';
|
2 |
| -import {bundle, assertBundleTree, run, outputFS} from '@parcel/test-utils'; |
| 2 | +import path from 'path'; |
| 3 | +import { |
| 4 | + bundle, |
| 5 | + distDir, |
| 6 | + assertBundles, |
| 7 | + run, |
| 8 | + outputFS, |
| 9 | +} from '@parcel/test-utils'; |
3 | 10 |
|
4 |
| -describe.skip('elm', function() { |
| 11 | +describe('elm', function() { |
5 | 12 | it('should produce a basic Elm bundle', async function() {
|
6 |
| - let b = await bundle(__dirname + '/integration/elm/index.js'); |
| 13 | + let b = await bundle(path.join(__dirname, '/integration/elm/index.js')); |
7 | 14 |
|
8 |
| - await assertBundleTree(b, { |
9 |
| - type: 'js', |
10 |
| - assets: ['Main.elm', 'index.js'], |
11 |
| - }); |
| 15 | + await assertBundles(b, [ |
| 16 | + { |
| 17 | + type: 'js', |
| 18 | + assets: ['Main.elm', 'index.js'], |
| 19 | + }, |
| 20 | + ]); |
12 | 21 |
|
13 | 22 | let output = await run(b);
|
14 | 23 | assert.equal(typeof output().Elm.Main.init, 'function');
|
15 | 24 | });
|
16 | 25 | it('should produce a elm bundle with debugger', async function() {
|
17 |
| - let b = await bundle(__dirname + '/integration/elm/index.js'); |
| 26 | + let b = await bundle(path.join(__dirname, '/integration/elm/index.js')); |
18 | 27 |
|
19 | 28 | await run(b);
|
20 |
| - let js = await outputFS.readFile(__dirname + '/dist/index.js', 'utf8'); |
| 29 | + let js = await outputFS.readFile(path.join(distDir, 'index.js'), 'utf8'); |
21 | 30 | assert(js.includes('elm$browser$Debugger'));
|
22 | 31 | });
|
23 | 32 |
|
24 | 33 | it('should apply elm-hot if HMR is enabled', async function() {
|
25 |
| - let b = await bundle(__dirname + '/integration/elm/index.js', { |
26 |
| - hmr: true, |
| 34 | + let b = await bundle(path.join(__dirname, '/integration/elm/index.js'), { |
| 35 | + hot: true, |
27 | 36 | });
|
28 | 37 |
|
29 |
| - await assertBundleTree(b, { |
30 |
| - type: 'js', |
31 |
| - assets: ['Main.elm', 'hmr-runtime.js', 'index.js'], |
32 |
| - }); |
| 38 | + await assertBundles(b, [ |
| 39 | + { |
| 40 | + type: 'js', |
| 41 | + assets: ['HMRRuntime.js', 'Main.elm', 'index.js'], |
| 42 | + }, |
| 43 | + ]); |
33 | 44 |
|
34 |
| - let js = await outputFS.readFile(__dirname + '/dist/index.js', 'utf8'); |
| 45 | + let js = await outputFS.readFile(path.join(distDir, 'index.js'), 'utf8'); |
35 | 46 | assert(js.includes('[elm-hot]'));
|
36 | 47 | });
|
37 | 48 |
|
38 | 49 | it('should remove debugger in production', async function() {
|
39 |
| - let b = await bundle(__dirname + '/integration/elm/index.js', { |
40 |
| - production: true, |
| 50 | + let b = await bundle(path.join(__dirname, '/integration/elm/index.js'), { |
| 51 | + mode: 'production', |
41 | 52 | });
|
42 | 53 |
|
43 | 54 | await run(b);
|
44 |
| - let js = await outputFS.readFile(__dirname + '/dist/index.js', 'utf8'); |
| 55 | + let js = await outputFS.readFile(path.join(distDir, 'index.js'), 'utf8'); |
| 56 | + assert(!js.includes('elm$browser$Debugger')); |
| 57 | + }); |
| 58 | + |
| 59 | + it('should remove debugger when environment variable `PARCEL_ELM_NO_DEBUG` is set to true', async function() { |
| 60 | + let b = await bundle(path.join(__dirname, '/integration/elm/index.js'), { |
| 61 | + env: {PARCEL_ELM_NO_DEBUG: true}, |
| 62 | + }); |
| 63 | + |
| 64 | + await run(b); |
| 65 | + let js = await outputFS.readFile(path.join(distDir, 'index.js'), 'utf8'); |
45 | 66 | assert(!js.includes('elm$browser$Debugger'));
|
46 | 67 | });
|
47 | 68 |
|
48 | 69 | it('should minify Elm in production mode', async function() {
|
49 |
| - let b = await bundle(__dirname + '/integration/elm/index.js', { |
50 |
| - production: true, |
| 70 | + let b = await bundle(path.join(__dirname, '/integration/elm/index.js'), { |
| 71 | + mode: 'production', |
| 72 | + minify: true, |
51 | 73 | });
|
52 | 74 |
|
53 |
| - let output = await run(b); |
54 |
| - assert.equal(typeof output().Elm.Main.init, 'function'); |
| 75 | + await run(b); |
55 | 76 |
|
56 |
| - let js = await outputFS.readFile(__dirname + '/dist/index.js', 'utf8'); |
| 77 | + let js = await outputFS.readFile(path.join(distDir, 'index.js'), 'utf8'); |
57 | 78 | assert(!js.includes('elm$core'));
|
| 79 | + assert(js.includes('Elm')); |
| 80 | + assert(js.includes('init')); |
58 | 81 | });
|
59 | 82 | });
|
0 commit comments