1- import { promises as fs } from 'fs' ;
1+ import { promises as fs } from 'node: fs' ;
22import touch from 'touch' ;
3- import camelcase from 'camelcase' ;
4- import mustache from 'mustache' ;
53import { dialects , projectTypes } from '@form8ion/javascript-core' ;
64
7- import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest' ;
5+ import { describe , expect , it , vi } from 'vitest' ;
86import any from '@travi/any' ;
97import { when } from 'jest-when' ;
108
11- import templatePath from '../../template-path.js' ;
129import { scaffold as scaffoldBundler } from '../publishable/bundler/index.js' ;
1310import buildDetails from './build-details.js' ;
1411
15- vi . mock ( 'fs' ) ;
12+ vi . mock ( 'node: fs' ) ;
1613vi . mock ( 'make-dir' ) ;
17- vi . mock ( 'camelcase' ) ;
18- vi . mock ( 'mustache' ) ;
1914vi . mock ( 'touch' ) ;
20- vi . mock ( '../../template-path' ) ;
2115vi . mock ( '../publishable/bundler' ) ;
2216
2317describe ( 'package build details' , ( ) => {
2418 const projectRoot = any . string ( ) ;
2519 const projectName = any . word ( ) ;
2620 const pathToExample = `${ projectRoot } /example.js` ;
2721 const bundlerResults = any . simpleObject ( ) ;
28- const exampleContent = any . string ( ) ;
29- const pathToExampleTemplate = any . string ( ) ;
30- const exampleTemplateContent = any . string ( ) ;
31- const camelizedProjectName = any . word ( ) ;
3222 const packageBundlers = any . simpleObject ( ) ;
3323 const decisions = any . simpleObject ( ) ;
3424
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-
4525 it ( 'should correctly define a common-js project' , async ( ) => {
4626 const results = await buildDetails ( {
4727 dialect : dialects . COMMON_JS ,
@@ -51,7 +31,7 @@ describe('package build details', () => {
5131 } ) ;
5232
5333 expect ( results ) . toEqual ( { } ) ;
54- expect ( fs . writeFile ) . toHaveBeenCalledWith ( pathToExample , ` const ${ camelizedProjectName } = require('.');\n` ) ;
34+ expect ( fs . writeFile ) . toHaveBeenCalledWith ( pathToExample , " const { } = require('.');\n" ) ;
5535 expect ( touch ) . toHaveBeenCalledWith ( `${ projectRoot } /index.js` ) ;
5636 } ) ;
5737
@@ -71,9 +51,6 @@ describe('package build details', () => {
7151 when ( scaffoldBundler )
7252 . calledWith ( { bundlers : packageBundlers , decisions, projectRoot, dialect, projectType : projectTypes . PACKAGE } )
7353 . mockResolvedValue ( bundlerResults ) ;
74- when ( mustache . render )
75- . calledWith ( exampleTemplateContent , { projectName : camelizedProjectName , esm : false } )
76- . mockReturnValue ( exampleContent ) ;
7754
7855 const results = await buildDetails ( {
7956 dialect,
@@ -100,7 +77,7 @@ describe('package build details', () => {
10077 } ) ;
10178 expect ( fs . mkdir ) . toHaveBeenCalledWith ( `${ projectRoot } /src` , { recursive : true } ) ;
10279 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" ) ;
10481 } ) ;
10582
10683 it ( 'should not create the example file for a modern-js project when `provideExample` is `false`' , async ( ) => {
0 commit comments