Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: usage of ESM imports (WIP) #6

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 7 additions & 10 deletions .scripts/generer-exercice.js
@@ -1,5 +1,5 @@
const path = require('path');
const fs = require('fs');
import path from 'path';
import fs from 'fs';

// Si le script est renommé ou change de dossier, on récupère les infos dynamiquement
const [ , cheminAbsoluDuScript, lettreNiveauDifficulte] = process.argv;
Expand Down Expand Up @@ -77,7 +77,7 @@ function chercherDossierNiveauDifficulte(cheminAbsolu, niveauDifficulte) {
repertoireCourant = path.dirname(repertoireCourant);
}
} while (repertoireCourant !== path.sep || repertoireCourant.length === 0);

// Si on arrive ici, c'est qu'on n'a pas trouvé le dossier !
return null;
}
Expand All @@ -97,7 +97,7 @@ function calculerNumeroProchainExercice(dossier) {
if (listeDossiersExercices.length === 0) {
return 0;
}

// On récupère les nombres de tous les dossiers
listeNumeros = listeDossiersExercices.reduce(function(acc, nomRepertoire) {
const dernierePartieDuNom = nomRepertoire.split('-').pop();
Expand Down Expand Up @@ -131,14 +131,11 @@ function creerFichiersNouvelExercice(cheminAbsoluDossierNouvelExercice, numeroEx
## Exemples
- `;

const contenuFichierJavaScript = `function exercice${numeroExercice}() {

}
const contenuFichierJavaScript = `export function exercice${numeroExercice}() {

// Ne touchez pas à la ligne suivante
module.exports = exercice${numeroExercice};`;
}`;

const contenuFichierTest = `const exercice${numeroExercice} = require('./exercice-${numeroExercice}');
const contenuFichierTest = `import { exercice${numeroExercice} } from './exercice-${numeroExercice}.js';

test('', () => {
expect(exercice${numeroExercice}()).toBe();
Expand Down
3 changes: 2 additions & 1 deletion .vscode/launch.json
Expand Up @@ -7,6 +7,7 @@
"name": "Tester",
"program": "${workspaceFolder}/node_modules/jest/bin/jest.js",
// Voir https://jestjs.io/docs/en/cli pour comprendre les arguments ci-dessous
"runtimeArgs": ["--experimental-vm-modules"],
"args": [
"--runInBand",
"--colors",
Expand All @@ -19,4 +20,4 @@
"console": "integratedTerminal",
}
]
}
}
7 changes: 2 additions & 5 deletions 00-facile/exercice-0/exercice-0.js
@@ -1,6 +1,3 @@
function exercice0() {

}
export function exercice0() {

// Ne touchez pas à la ligne suivante
module.exports = exercice0;
}
3 changes: 1 addition & 2 deletions 00-facile/exercice-0/exercice-0.test.js
@@ -1,6 +1,5 @@
const exercice0 = require('./exercice-0');
import { exercice0 } from './exercice-0.js';

test('retourne Coding Dojo', () => {
expect(exercice0()).toBe("Coding Dojo");
});