1
- import { promises as fs } from 'fs' ;
1
+ import { promises as fs } from 'node: fs' ;
2
2
import touch from 'touch' ;
3
- import camelcase from 'camelcase' ;
4
- import mustache from 'mustache' ;
5
3
import { dialects , projectTypes } from '@form8ion/javascript-core' ;
6
4
7
- import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest' ;
5
+ import { describe , expect , it , vi } from 'vitest' ;
8
6
import any from '@travi/any' ;
9
7
import { when } from 'jest-when' ;
10
8
11
- import templatePath from '../../template-path.js' ;
12
9
import { scaffold as scaffoldBundler } from '../publishable/bundler/index.js' ;
13
10
import buildDetails from './build-details.js' ;
14
11
15
- vi . mock ( 'fs' ) ;
12
+ vi . mock ( 'node: fs' ) ;
16
13
vi . mock ( 'make-dir' ) ;
17
- vi . mock ( 'camelcase' ) ;
18
- vi . mock ( 'mustache' ) ;
19
14
vi . mock ( 'touch' ) ;
20
- vi . mock ( '../../template-path' ) ;
21
15
vi . mock ( '../publishable/bundler' ) ;
22
16
23
17
describe ( 'package build details' , ( ) => {
24
18
const projectRoot = any . string ( ) ;
25
19
const projectName = any . word ( ) ;
26
20
const pathToExample = `${ projectRoot } /example.js` ;
27
21
const bundlerResults = any . simpleObject ( ) ;
28
- const exampleContent = any . string ( ) ;
29
- const pathToExampleTemplate = any . string ( ) ;
30
- const exampleTemplateContent = any . string ( ) ;
31
- const camelizedProjectName = any . word ( ) ;
32
22
const packageBundlers = any . simpleObject ( ) ;
33
23
const decisions = any . simpleObject ( ) ;
34
24
35
- beforeEach ( ( ) => {
36
- when ( templatePath ) . calledWith ( 'example.mustache' ) . mockReturnValue ( pathToExampleTemplate ) ;
37
- when ( fs . readFile ) . calledWith ( pathToExampleTemplate , 'utf8' ) . mockResolvedValue ( exampleTemplateContent ) ;
38
- when ( camelcase ) . calledWith ( projectName ) . mockReturnValue ( camelizedProjectName ) ;
39
- } ) ;
40
-
41
- afterEach ( ( ) => {
42
- vi . clearAllMocks ( ) ;
43
- } ) ;
44
-
45
25
it ( 'should correctly define a common-js project' , async ( ) => {
46
26
const results = await buildDetails ( {
47
27
dialect : dialects . COMMON_JS ,
@@ -51,7 +31,7 @@ describe('package build details', () => {
51
31
} ) ;
52
32
53
33
expect ( results ) . toEqual ( { } ) ;
54
- expect ( fs . writeFile ) . toHaveBeenCalledWith ( pathToExample , ` const ${ camelizedProjectName } = require('.');\n` ) ;
34
+ expect ( fs . writeFile ) . toHaveBeenCalledWith ( pathToExample , " const { } = require('.');\n" ) ;
55
35
expect ( touch ) . toHaveBeenCalledWith ( `${ projectRoot } /index.js` ) ;
56
36
} ) ;
57
37
@@ -71,9 +51,6 @@ describe('package build details', () => {
71
51
when ( scaffoldBundler )
72
52
. calledWith ( { bundlers : packageBundlers , decisions, projectRoot, dialect, projectType : projectTypes . PACKAGE } )
73
53
. mockResolvedValue ( bundlerResults ) ;
74
- when ( mustache . render )
75
- . calledWith ( exampleTemplateContent , { projectName : camelizedProjectName , esm : false } )
76
- . mockReturnValue ( exampleContent ) ;
77
54
78
55
const results = await buildDetails ( {
79
56
dialect,
@@ -100,7 +77,7 @@ describe('package build details', () => {
100
77
} ) ;
101
78
expect ( fs . mkdir ) . toHaveBeenCalledWith ( `${ projectRoot } /src` , { recursive : true } ) ;
102
79
expect ( touch ) . toHaveBeenCalledWith ( `${ projectRoot } /src/index.js` ) ;
103
- expect ( fs . writeFile ) . toHaveBeenCalledWith ( pathToExample , exampleContent ) ;
80
+ expect ( fs . writeFile ) . toHaveBeenCalledWith ( pathToExample , "import {} from './lib/index.js';\n" ) ;
104
81
} ) ;
105
82
106
83
it ( 'should not create the example file for a modern-js project when `provideExample` is `false`' , async ( ) => {
0 commit comments