Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
styfle committed Mar 18, 2022
1 parent ba4c657 commit 1051ee6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
21 changes: 20 additions & 1 deletion test/unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ for (const { testName, isRoot } of unitTests) {
}

if (testName === 'multi-input') {
inputFileNames.push('input-2.js', 'input-3.js')
inputFileNames.push('input-2.js', 'input-3.js', 'input-4.js');
}

const { fileList, reasons } = await nodeFileTrace(
Expand Down Expand Up @@ -129,6 +129,25 @@ for (const { testName, isRoot } of unitTests) {
"test/unit/multi-input/asset.txt",
"test/unit/multi-input/child-3.js",
])

expect([...collectFiles(normalizeInputRoot('input-4.js'))].map(normalizeFilesRoot).sort()).toEqual([
"package.json",
"test/unit/multi-input/child-4.js",
"test/unit/multi-input/style.module.css",
])

expect(reasons.get('test/unit/multi-input/input.js').type).toEqual(['initial', 'dependency'])
expect(reasons.get('test/unit/multi-input/input-2.js').type).toEqual(['initial', 'dependency'])
expect(reasons.get('test/unit/multi-input/input-3.js').type).toEqual(['initial', 'dependency'])
expect(reasons.get('test/unit/multi-input/input-4.js').type).toEqual(['initial', 'dependency'])
expect(reasons.get('test/unit/multi-input/child-1.js').type).toEqual(['dependency'])
expect(reasons.get('test/unit/multi-input/child-2.js').type).toEqual(['dependency'])
expect(reasons.get('test/unit/multi-input/child-3.js').type).toEqual(['dependency'])
expect(reasons.get('test/unit/multi-input/child-4.js').type).toEqual(['dependency'])
expect(reasons.get('test/unit/multi-input/asset.txt').type).toEqual(['asset'])
expect(reasons.get('test/unit/multi-input/asset-2.txt').type).toEqual(['asset'])
expect(reasons.get('test/unit/multi-input/style.module.css').type).toEqual(['dependency', 'asset'])

}

let expected;
Expand Down
4 changes: 4 additions & 0 deletions test/unit/multi-input/child-4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const fs = require('fs')
const { join } = require('path')

fs.readFileSync(join(__dirname, 'style.module.css'))
3 changes: 3 additions & 0 deletions test/unit/multi-input/input-4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import style from './style.module.css';

import child4 from './child-4';
5 changes: 4 additions & 1 deletion test/unit/multi-input/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"test/unit/multi-input/child-1.js",
"test/unit/multi-input/child-2.js",
"test/unit/multi-input/child-3.js",
"test/unit/multi-input/child-4.js",
"test/unit/multi-input/input-2.js",
"test/unit/multi-input/input-3.js",
"test/unit/multi-input/input.js"
"test/unit/multi-input/input-4.js",
"test/unit/multi-input/input.js",
"test/unit/multi-input/style.module.css"
]
1 change: 1 addition & 0 deletions test/unit/multi-input/style.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body { color: green; }

0 comments on commit 1051ee6

Please sign in to comment.