-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(taro-runner-utils): 添加单元测试和优化注释
- Loading branch information
1 parent
991588d
commit 0f65793
Showing
10 changed files
with
4,353 additions
and
58 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
packages/taro-runner-utils/__tests__/__snapshots__/scss.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`getBundleContent test sass resource array 1`] = ` | ||
"$color-ui-info: #78A4FA !default; | ||
$color-ui-positive: #13CE66 !default; | ||
$color-ui-negative: #FF4949 !default; | ||
$color-ui-warning: #FFC82C !default; | ||
@mixin transform($property) { | ||
-webkit-transform: $property; | ||
-ms-transform: $property; | ||
transform: $property; | ||
} | ||
" | ||
`; | ||
|
||
exports[`getBundleContent test sass resource array with directory 1`] = ` | ||
"$color-ui-info: #78A4FA !default; | ||
$color-ui-positive: #13CE66 !default; | ||
$color-ui-negative: #FF4949 !default; | ||
$color-ui-warning: #FFC82C !default; | ||
@mixin transform($property) { | ||
-webkit-transform: $property; | ||
-ms-transform: $property; | ||
transform: $property; | ||
} | ||
" | ||
`; | ||
|
||
exports[`getBundleContent test sass resource path 1`] = ` | ||
"$color-ui-info: #78A4FA !default; | ||
$color-ui-positive: #13CE66 !default; | ||
$color-ui-negative: #FF4949 !default; | ||
$color-ui-warning: #FFC82C !default; | ||
" | ||
`; | ||
|
||
exports[`getBundleContent test sass resource path with directory 1`] = ` | ||
"$color-ui-info: #78A4FA !default; | ||
$color-ui-positive: #13CE66 !default; | ||
$color-ui-negative: #FF4949 !default; | ||
$color-ui-warning: #FFC82C !default; | ||
" | ||
`; | ||
|
||
exports[`getBundleResult test file name and project directory path 1`] = ` | ||
"$color-ui-info: #78A4FA !default; | ||
$color-ui-positive: #13CE66 !default; | ||
$color-ui-negative: #FF4949 !default; | ||
$color-ui-warning: #FFC82C !default; | ||
" | ||
`; | ||
|
||
exports[`getBundleResult test file path 1`] = ` | ||
"$color-ui-info: #78A4FA !default; | ||
$color-ui-positive: #13CE66 !default; | ||
$color-ui-negative: #FF4949 !default; | ||
$color-ui-warning: #FFC82C !default; | ||
" | ||
`; | ||
|
||
exports[`getSassLoaderOption test get sass loader option 1`] = ` | ||
Object { | ||
"data": "$color-ui-info: #78A4FA !default; | ||
$color-ui-positive: #13CE66 !default; | ||
$color-ui-negative: #FF4949 !default; | ||
$color-ui-warning: #FFC82C !default; | ||
@mixin transform($property) { | ||
-webkit-transform: $property; | ||
-ms-transform: $property; | ||
transform: $property; | ||
} | ||
", | ||
"implementation": "dart-sass", | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import path from 'path' | ||
import { getBundleResult, getBundleContent, getSassLoaderOption } from '../dist/index' | ||
|
||
describe('getBundleResult', () => { | ||
const filePath = path.resolve(__dirname, '.', 'styles/variables.scss') | ||
const fileConfig = { | ||
name: 'styles/variables.scss', | ||
path: path.resolve(__dirname, '.') | ||
} | ||
|
||
test('test file path', async () => { | ||
const res = await getBundleResult(filePath) | ||
expect(res.bundledContent).toMatchSnapshot() | ||
}) | ||
|
||
test('test file name and project directory path', async () => { | ||
const res = await getBundleResult(fileConfig.name, fileConfig.path) | ||
expect(res.bundledContent).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
describe('getBundleContent', () => { | ||
const sassResourcePath = { | ||
resource: path.resolve(__dirname, '.', 'styles/variables.scss') | ||
} | ||
const sassResourcePathWithDirectory = { | ||
resource: 'styles/variables.scss', | ||
projectDirectory: path.resolve(__dirname, '.') | ||
} | ||
const sassResourceArray = { | ||
resource: [ | ||
path.resolve(__dirname, '.', 'styles/variables.scss'), | ||
path.resolve(__dirname, '.', 'styles/mixins.scss') | ||
] | ||
} | ||
const sassResourceArrayWithDirectory = { | ||
resource: [ | ||
'styles/variables.scss', | ||
'styles/mixins.scss' | ||
], | ||
projectDirectory: path.resolve(__dirname, '.') | ||
} | ||
|
||
test('test sass resource path', async () => { | ||
const data = sassResourcePath; | ||
const res = await getBundleContent(data.resource) | ||
expect(res).toMatchSnapshot() | ||
}) | ||
test('test sass resource path with directory', async () => { | ||
const data = sassResourcePathWithDirectory | ||
const res = await getBundleContent(data.resource, data.projectDirectory) | ||
expect(res).toMatchSnapshot() | ||
}) | ||
|
||
test('test sass resource array', async () => { | ||
const data = sassResourceArray; | ||
const res = await getBundleContent(data.resource) | ||
expect(res).toMatchSnapshot() | ||
}) | ||
test('test sass resource array with directory', async () => { | ||
const data = sassResourceArrayWithDirectory | ||
const res = await getBundleContent(data.resource, data.projectDirectory) | ||
expect(res).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
describe('getSassLoaderOption', () => { | ||
const buildConfig = { | ||
publicPath: '/', | ||
staticDirectory: 'static', | ||
deviceRatio: { '640': 1.17, '750': 1, '828': 0.905 }, | ||
designWidth: 750, | ||
outputRoot: 'dist', | ||
sass: { | ||
resource: [ | ||
'styles/variables.scss', | ||
'styles/mixins.scss' | ||
], | ||
projectDirectory: path.resolve(__dirname, '.') | ||
}, | ||
sassLoaderOption: { | ||
implementation: 'dart-sass' | ||
}, | ||
sourceRoot: 'src' | ||
} | ||
|
||
test('test get sass loader option', async () => { | ||
const res = await getSassLoaderOption(buildConfig) | ||
expect(res).toMatchSnapshot() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@mixin transform($property) { | ||
-webkit-transform: $property; | ||
-ms-transform: $property; | ||
transform: $property; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
$color-ui-info: #78A4FA !default; | ||
$color-ui-positive: #13CE66 !default; | ||
$color-ui-negative: #FF4949 !default; | ||
$color-ui-warning: #FFC82C !default; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
targets: { | ||
node: 'current', | ||
}, | ||
}, | ||
], | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
verbose: true, | ||
moduleFileExtensions: ['js', 'jsx', 'json'], | ||
rootDir: __dirname, | ||
testMatch: ['<rootDir>/__tests__/**/*.test.js'], | ||
transform: { | ||
'^.+\\.js?$': 'babel-jest' | ||
}, | ||
transformIgnorePatterns: ['<rootDir>/node_modules/'] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.