1+ import { mkdtempSync , writeFileSync } from 'fs' ;
2+ import { tmpdir } from 'os' ;
3+ import path from 'path' ;
14import { describe , expect , it } from 'vitest' ;
2- import { createConfigForIDFProject } from './idfProjectConfig.js' ;
5+ import { createConfigForIDFProject , idfProjectConfig } from './idfProjectConfig.js' ;
36
47describe ( 'createConfigForIDFProject' , ( ) => {
58 it ( 'should create a config for an IDF project' , ( ) => {
@@ -20,3 +23,50 @@ describe('createConfigForIDFProject', () => {
2023 ` ) ;
2124 } ) ;
2225} ) ;
26+
27+ describe ( 'idfProjectConfig' , ( ) => {
28+ function setupTempProject ( boardType : string , idfTarget : string ) {
29+ const dir = mkdtempSync ( path . join ( tmpdir ( ) , 'wokwi-test-' ) ) ;
30+ const diagramPath = path . join ( dir , 'diagram.json' ) ;
31+ const projectDescPath = path . join ( dir , 'project_description.json' ) ;
32+ const configPath = path . join ( dir , 'wokwi.toml' ) ;
33+ writeFileSync (
34+ diagramPath ,
35+ JSON . stringify ( { version : 1 , parts : [ { type : boardType , id : 'esp' } ] , connections : [ ] } ) ,
36+ ) ;
37+ writeFileSync ( projectDescPath , JSON . stringify ( { target : idfTarget } ) ) ;
38+ return { dir, diagramPath, projectDescPath, configPath } ;
39+ }
40+
41+ it ( 'should accept esp32-s3-box-3 diagram with esp32s3 IDF target' , ( ) => {
42+ const { dir, diagramPath, projectDescPath, configPath } = setupTempProject (
43+ 'board-esp32-s3-box-3' ,
44+ 'esp32s3' ,
45+ ) ;
46+
47+ const result = idfProjectConfig ( {
48+ rootDir : dir ,
49+ configPath,
50+ diagramFilePath : diagramPath ,
51+ projectDescriptionPath : projectDescPath ,
52+ } ) ;
53+
54+ expect ( result ) . toBe ( true ) ;
55+ } ) ;
56+
57+ it ( 'should reject esp32-s3-box-3 diagram with esp32 IDF target' , ( ) => {
58+ const { dir, diagramPath, projectDescPath, configPath } = setupTempProject (
59+ 'board-esp32-s3-box-3' ,
60+ 'esp32' ,
61+ ) ;
62+
63+ const result = idfProjectConfig ( {
64+ rootDir : dir ,
65+ configPath,
66+ diagramFilePath : diagramPath ,
67+ projectDescriptionPath : projectDescPath ,
68+ } ) ;
69+
70+ expect ( result ) . toBe ( false ) ;
71+ } ) ;
72+ } ) ;
0 commit comments