Skip to content

Commit

Permalink
feat: rewrite test files
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbate committed Jul 12, 2024
1 parent da35aad commit 04dd9d5
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/create-fuels/src/lib/rewriteTemplateFiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,33 @@ describe('rewriteTemplateFiles', () => {
expect(fuelsConfig).not.toContain(/\n\W+forcPath: 'fuels-forc',/g);
expect(fuelsConfig).not.toContain(/\n\W+fuelCorePath: 'fuels-core',/g);
});

it('should rewrite the test files', () => {
const testDir = join(paths.template, 'test');
const programs = [
{
program: 'contract',
capitalised: 'Contract',
},
{
program: 'predicate',
capitalised: 'Predicate',
},
{
program: 'script',
capitalised: 'Script',
},
];

rewriteTemplateFiles(paths.template);

programs.forEach(({ program, capitalised }) => {
const testFilePath = join(testDir, `${program}.test.ts`);
const testFileContents = readFileSync(testFilePath, 'utf-8');

expect(testFileContents).not.toContain('@group node');
expect(testFileContents).not.toContain('@group browser');
expect(testFileContents).toContain(`${capitalised} Testing`);
});
});
});
12 changes: 12 additions & 0 deletions packages/create-fuels/src/lib/rewriteTemplateFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,16 @@ export const rewriteTemplateFiles = (templateDir: string) => {
contents = contents.replace(/\n\W+forcPath: 'fuels-forc',/g, '');
contents = contents.replace(/\n\W+fuelCorePath: 'fuels-core',/g, '');
writeFileSync(fuelsConfigFilePath, contents);

// tests
const testDir = join(templateDir, 'test');
const programs = ['contract', 'predicate', 'script'];
programs.forEach((program) => {
const testFilePath = join(testDir, `${program}.test.ts`);
contents = readFileSync(testFilePath, 'utf-8');
const capitalisedProgram = program.charAt(0).toUpperCase() + program.slice(1);
contents = contents.replace(/@group node/g, `${capitalisedProgram} Testing`);
contents = contents.replace(/@group browser/g, '');
writeFileSync(testFilePath, contents);
});
};
1 change: 1 addition & 0 deletions templates/nextjs/test/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import bytecode from '../src/sway-api/contracts/TestContractAbi.hex';

/**
* @group node
* @group browser
*
* Tests for the contract program type within the TS SDK. Here we will test the deployment of
* our contract, and the result of call it's functions.
Expand Down
1 change: 1 addition & 0 deletions templates/nextjs/test/predicate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { TestPredicateAbi__factory, TestPredicateAbiInputs } from '../src/sway-a

/**
* @group node
* @group browser
*
* Tests for the predicate program type within the TS SDK. Here we will test the use of our predicate
* in a transaction.
Expand Down
1 change: 1 addition & 0 deletions templates/nextjs/test/script.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { TestScriptAbi__factory } from '../src/sway-api';

/**
* @group node
* @group browser
*
* Tests for the script program type within the TS SDK. Here we will test the use of our script
* function call.
Expand Down

0 comments on commit 04dd9d5

Please sign in to comment.