11import os from "os" ;
2- import path from "path" ;
32import fs , { existsSync } from "fs" ;
43import functions from "../ts/functions" ;
54import { Tmc } from "../ts/tmc" ;
@@ -41,8 +40,8 @@ async function initWithTempDir(): Promise<Tmc> {
4140 "mock-client" ,
4241 "mock-version" ,
4342 addr ,
44- path . join ( tempDir , "config" ) ,
45- path . join ( tempDir , "projects" )
43+ [ tempDir , "config" ] . join ( "/ ") ,
44+ [ tempDir , "projects" ] . join ( "/ ")
4645 ) ;
4746 tmc . loginWithToken ( "" ) ;
4847 return tmc ;
@@ -53,8 +52,8 @@ async function writeFiles(
5352 files : ( [ string ] | [ string , string ] ) [ ]
5453) {
5554 for await ( const [ relative , contents ] of files ) {
56- const p = path . join ( root , relative ) ;
57- const dir = path . join ( p , "../" ) ;
55+ const p = [ root , relative ] . join ( "/" ) ;
56+ const dir = [ p , "../" ] . join ( " /") ;
5857 await fs . promises . mkdir ( dir , { recursive : true } ) ;
5958 if ( contents == undefined ) {
6059 await fs . promises . writeFile ( p , "" ) ;
@@ -65,19 +64,21 @@ async function writeFiles(
6564}
6665
6766async function tempdir ( ) : Promise < string > {
68- return fs . promises . mkdtemp ( path . join ( os . tmpdir ( ) , "langs_jest_" ) ) ;
67+ return fs . promises . mkdtemp ( [ os . tmpdir ( ) . split ( "\\" ) . join ( "/" ) , "langs_jest_" ] . join ( "/ ") ) ;
6968}
7069
7170async function mockEnvironment ( tmc : Tmc ) {
72- const clientConfigDir = path . join ( tmc . configDir ! , `tmc-${ tmc . clientName } ` ) ;
73- const clientProjectsDir = path . join ( tmc . defaultProjectsDir ! , tmc . clientName ) ;
71+ const clientConfigDir = [ tmc . configDir ! , `tmc-${ tmc . clientName } ` ] . join ( "/" ) ;
72+ const clientProjectsDir = [ tmc . defaultProjectsDir ! , tmc . clientName ] . join ( "/" ) ;
73+ console . log ( "creating mock config at " + clientConfigDir ) ;
7474 await writeFiles ( clientConfigDir , [
7575 [ "config.toml" , `
7676projects_dir = "${ clientProjectsDir } "
7777setting = "value"
7878` ]
7979 ] )
8080
81+ console . log ( "creating mock projects dir at " + clientProjectsDir ) ;
8182 await writeFiles ( clientProjectsDir , [
8283 [
8384 "some course/course_config.toml" ,
@@ -94,8 +95,8 @@ checksum = 'new checksum'
9495` ,
9596 ] ,
9697 ] ) ;
97- await mockExercise ( path . join ( clientProjectsDir , "some course/on disk exercise with update and submission" ) ) ;
98- await mockExercise ( path . join ( clientProjectsDir , "some course/on disk exercise without update" ) ) ;
98+ await mockExercise ( [ clientProjectsDir , "some course/on disk exercise with update and submission" ] . join ( "/ ") ) ;
99+ await mockExercise ( [ clientProjectsDir , "some course/on disk exercise without update" ] . join ( "/ ") ) ;
99100}
100101
101102async function mockExercise ( dir ?: string ) : Promise < string > {
@@ -127,27 +128,27 @@ test("cleans", async () => {
127128 const tmc = init ( ) ;
128129
129130 const dir = await mockExercise ( ) ;
130- expect ( fs . existsSync ( path . join ( dir , "__pycache__/cachefile" ) ) ) . toBeTruthy ( ) ;
131+ expect ( fs . existsSync ( [ dir , "__pycache__/cachefile" ] . join ( "/ ") ) ) . toBeTruthy ( ) ;
131132 tmc . clean ( dir ) ;
132- expect ( fs . existsSync ( path . join ( dir , "__pycache__/cachefile" ) ) ) . toBeFalsy ( ) ;
133+ expect ( fs . existsSync ( [ dir , "__pycache__/cachefile" ] . join ( "/ ") ) ) . toBeFalsy ( ) ;
133134} ) ;
134135
135136test ( "compresses project" , async ( ) => {
136137 const tmc = init ( ) ;
137138
138139 const dir = await mockExercise ( ) ;
139- expect ( fs . existsSync ( path . join ( dir , "output.zip" ) ) ) . toBeFalsy ( ) ;
140- tmc . compressProject ( dir , path . join ( dir , "output.zip" ) ) ;
141- expect ( fs . existsSync ( path . join ( dir , "output.zip" ) ) ) . toBeTruthy ( ) ;
140+ expect ( fs . existsSync ( [ dir , "output.zip" ] . join ( "/ ") ) ) . toBeFalsy ( ) ;
141+ tmc . compressProject ( dir , [ dir , "output.zip" ] . join ( "/ ") ) ;
142+ expect ( fs . existsSync ( [ dir , "output.zip" ] . join ( "/ ") ) ) . toBeTruthy ( ) ;
142143} ) ;
143144
144145test ( "extracts project" , async ( ) => {
145146 const tmc = init ( ) ;
146147
147148 const dir = await tempdir ( ) ;
148- expect ( fs . existsSync ( path . join ( dir , "setup.py" ) ) ) . toBeFalsy ( ) ;
149+ expect ( fs . existsSync ( [ dir , "setup.py" ] . join ( "/ ") ) ) . toBeFalsy ( ) ;
149150 tmc . extractProject ( "jest/python-exercise.zip" , dir ) ;
150- expect ( fs . existsSync ( path . join ( dir , "setup.py" ) ) ) . toBeTruthy ( ) ;
151+ expect ( fs . existsSync ( [ dir , "setup.py" ] . join ( "/ ") ) ) . toBeTruthy ( ) ;
151152} ) ;
152153
153154test ( "finds points" , async ( ) => {
@@ -162,9 +163,10 @@ test("finds exercises", async () => {
162163 const tmc = init ( ) ;
163164
164165 const rootDir = await tempdir ( ) ;
165- const dir = await mockExercise ( path . join ( rootDir , "some" , "dirs" ) ) ;
166+ const dir = await mockExercise ( [ rootDir , "some" , "dirs" ] . join ( "/ ") ) ;
166167 const exercises = tmc . findExercises ( rootDir ) ;
167- expect ( exercises [ 0 ] ) . toEqual ( dir ) ;
168+ expect ( exercises [ 0 ] ) . toContain ( "some" ) ;
169+ expect ( exercises [ 0 ] ) . toContain ( "dirs" ) ;
168170} ) ;
169171
170172test ( "gets exercise packaging configuration" , async ( ) => {
@@ -190,19 +192,19 @@ test("prepares solutions", async () => {
190192
191193 const dir = await mockExercise ( ) ;
192194 const temp = await tempdir ( ) ;
193- expect ( fs . existsSync ( path . join ( temp , "src" ) ) ) . toBeFalsy ( ) ;
195+ expect ( fs . existsSync ( [ temp , "src" ] . join ( "/ ") ) ) . toBeFalsy ( ) ;
194196 tmc . prepareSolutions ( dir , temp ) ;
195- expect ( fs . existsSync ( path . join ( temp , "src" ) ) ) . toBeTruthy ( ) ;
197+ expect ( fs . existsSync ( [ temp , "src" ] . join ( "/ ") ) ) . toBeTruthy ( ) ;
196198} ) ;
197199
198200test ( "prepares stubs" , async ( ) => {
199201 const tmc = init ( ) ;
200202
201203 const dir = await mockExercise ( ) ;
202204 const temp = await tempdir ( ) ;
203- expect ( fs . existsSync ( path . join ( temp , "src" ) ) ) . toBeFalsy ( ) ;
205+ expect ( fs . existsSync ( [ temp , "src" ] . join ( "/ ") ) ) . toBeFalsy ( ) ;
204206 tmc . prepareStubs ( dir , temp ) ;
205- expect ( fs . existsSync ( path . join ( temp , "src" ) ) ) . toBeTruthy ( ) ;
207+ expect ( fs . existsSync ( [ temp , "src" ] . join ( "/ ") ) ) . toBeTruthy ( ) ;
206208} ) ;
207209
208210test . skip ( "prepares submission" , async ( ) => {
@@ -243,18 +245,18 @@ test("downloads model solutions", async () => {
243245 const tmc = init ( ) ;
244246
245247 const temp = await tempdir ( ) ;
246- expect ( existsSync ( path . join ( temp , "src" ) ) ) . toBeFalsy ( ) ;
248+ expect ( existsSync ( [ temp , "src" ] . join ( "/ ") ) ) . toBeFalsy ( ) ;
247249 tmc . downloadModelSolution ( 1 , temp ) ;
248- expect ( existsSync ( path . join ( temp , "src" ) ) ) . toBeTruthy ( ) ;
250+ expect ( existsSync ( [ temp , "src" ] . join ( "/ ") ) ) . toBeTruthy ( ) ;
249251} ) ;
250252
251253test ( "downloads old submission" , async ( ) => {
252254 const tmc = init ( ) ;
253255
254256 const temp = await tempdir ( ) ;
255- expect ( existsSync ( path . join ( temp , "src" ) ) ) . toBeFalsy ( ) ;
257+ expect ( existsSync ( [ temp , "src" ] . join ( "/ ") ) ) . toBeFalsy ( ) ;
256258 tmc . downloadOldSubmission ( 1 , false , 1 , temp ) ;
257- expect ( existsSync ( path . join ( temp , "src" ) ) ) . toBeTruthy ( ) ;
259+ expect ( existsSync ( [ temp , "src" ] . join ( "/ ") ) ) . toBeTruthy ( ) ;
258260} ) ;
259261
260262test ( "downloads or updates course exercises" , async ( ) => {
@@ -280,7 +282,7 @@ test("gets course details", async () => {
280282
281283test ( "gets course exercises" , async ( ) => {
282284 const tmc = init ( ) ;
283-
285+
284286 const courseExercises = tmc . getCourseExercises ( 1 ) ;
285287 expect ( courseExercises . length ) . toBeGreaterThan ( 0 ) ;
286288} ) ;
@@ -329,7 +331,7 @@ test("gets organizations", async () => {
329331
330332test ( "gets unread reviews" , async ( ) => {
331333 const tmc = init ( ) ;
332-
334+
333335 const unreadReviews = tmc . getUnreadReviews ( 1 ) ;
334336 expect ( unreadReviews . length ) . toBeGreaterThan ( 0 ) ;
335337} ) ;
0 commit comments