Skip to content

Commit

Permalink
Migrate most tests to the module system (#2003)
Browse files Browse the repository at this point in the history
  • Loading branch information
jathak committed Jul 8, 2024
1 parent 7ac8066 commit 81545a9
Show file tree
Hide file tree
Showing 280 changed files with 7,679 additions and 6,424 deletions.
49 changes: 49 additions & 0 deletions migrate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Script to run the Sass migrator over a spec directory.
//
// Usage:
// npm run migrate -- directory-to-migrate <migrator> [migrator-options]

import child_process from 'child_process';
import fs from 'fs';
import path from 'path';
import {fromRoot} from './lib/spec-directory';

async function migrate() {
const dirToMigrate = process.argv[2];
const migratorCommand = process.argv[3];
const migratorArgs = process.argv.slice(4);
const root = path.resolve(process.cwd(), 'spec');
const rootDir = await fromRoot('spec');

await rootDir.forEachTest(
async testDir => {
const files = (await testDir.listFiles()).filter(
file => file.endsWith('.scss') || file.endsWith('.sass')
);
console.log(testDir.relPath());
const output = child_process.execFileSync(
path.join(
__dirname,
'node_modules',
'sass-migrator',
'sass-migrator.js'
),
[migratorCommand, `--load-path=${root}`, ...migratorArgs, ...files],
{cwd: testDir.path, encoding: 'utf8'}
);
if (output.length > 0) console.log(output);
// Actually write the migrator's changes to the virtual directory's cache.
for (const file of files) {
await testDir.writeFile(
file,
await fs.promises.readFile(path.join(testDir.path, file), {
encoding: 'utf8',
})
);
}
},
[dirToMigrate]
);
}

migrate();
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"lodash": "^4.17.21",
"node-hrx": "^0.1.0",
"prettier": "^2.1.2",
"sass-migrator": "^2.0.3",
"source-map-js": "^0.6.2",
"tmp": "^0.2.1",
"ts-jest": "^27.0.7",
Expand All @@ -75,6 +76,7 @@
"test": "jest",
"lint-spec": "ts-node lint-spec.ts",
"lint": "gts lint",
"migrate": "ts-node migrate.ts",
"fix": "gts fix"
},
"engines": {
Expand Down
21 changes: 12 additions & 9 deletions spec/core_functions/color/adjust_color/error/args.hrx
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
<===> too_few/input.scss
a {b: adjust-color()}
@use "sass:color";
a {b: color.adjust()}

<===> too_few/error
Error: Missing argument $color.
,--> input.scss
1 | a {b: adjust-color()}
2 | a {b: color.adjust()}
| ^^^^^^^^^^^^^^ invocation
'
,--> sass:color
1 | @function adjust($color, $kwargs...) {
| ========================== declaration
'
input.scss 1:7 root stylesheet
input.scss 2:7 root stylesheet

<===>
================================================================================
<===> too_many/input.scss
a {b: adjust-color(red, 1)}
@use "sass:color";
a {b: color.adjust(red, 1)}

<===> too_many/error
Error: Only one positional argument is allowed. All other arguments must be passed by name.
,
1 | a {b: adjust-color(red, 1)}
2 | a {b: color.adjust(red, 1)}
| ^^^^^^^^^^^^^^^^^^^^
'
input.scss 1:7 root stylesheet
input.scss 2:7 root stylesheet

<===>
================================================================================
<===> unknown/input.scss
a {b: adjust-color(red, $ambience: 10%)}
@use "sass:color";
a {b: color.adjust(red, $ambience: 10%)}

<===> unknown/error
Error: No argument named $ambience.
,
1 | a {b: adjust-color(red, $ambience: 10%)}
2 | a {b: color.adjust(red, $ambience: 10%)}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'
input.scss 1:7 root stylesheet
input.scss 2:7 root stylesheet
Loading

0 comments on commit 81545a9

Please sign in to comment.